forked from wolfSSL/wolfssl
Maintenance: ASN.1
1. Fix some preprocessor flag checking for function EncodePolicyOID. It also needs to be available for OpenSSL Compatibility. 2. Fix for a name string for a test that can get left in or out incorrectly.
This commit is contained in:
@ -11414,87 +11414,6 @@ static int SetExtKeyUsage(Cert* cert, byte* output, word32 outSz, byte input)
|
||||
return idx;
|
||||
}
|
||||
|
||||
/* Encode OID string representation to ITU-T X.690 format */
|
||||
int EncodePolicyOID(byte *out, word32 *outSz, const char *in, void* heap)
|
||||
{
|
||||
word32 val, idx = 0, nb_val;
|
||||
char *token, *str, *ptr;
|
||||
word32 len;
|
||||
|
||||
(void)heap;
|
||||
|
||||
if (out == NULL || outSz == NULL || *outSz < 2 || in == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
/* duplicate string (including terminator) */
|
||||
len = (word32)XSTRLEN(in);
|
||||
str = (char *)XMALLOC(len+1, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (str == NULL)
|
||||
return MEMORY_E;
|
||||
XMEMCPY(str, in, len+1);
|
||||
|
||||
nb_val = 0;
|
||||
|
||||
/* parse value, and set corresponding Policy OID value */
|
||||
token = XSTRTOK(str, ".", &ptr);
|
||||
while (token != NULL)
|
||||
{
|
||||
val = (word32)XATOI(token);
|
||||
|
||||
if (nb_val == 0) {
|
||||
if (val > 2) {
|
||||
XFREE(str, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
return ASN_OBJECT_ID_E;
|
||||
}
|
||||
|
||||
out[idx] = (byte)(40 * val);
|
||||
}
|
||||
else if (nb_val == 1) {
|
||||
if (val > 127) {
|
||||
XFREE(str, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
return ASN_OBJECT_ID_E;
|
||||
}
|
||||
|
||||
if (idx > *outSz) {
|
||||
XFREE(str, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
return BUFFER_E;
|
||||
}
|
||||
|
||||
out[idx++] += (byte)val;
|
||||
}
|
||||
else {
|
||||
word32 tb = 0, x;
|
||||
int i = 0;
|
||||
byte oid[MAX_OID_SZ];
|
||||
|
||||
while (val >= 128) {
|
||||
x = val % 128;
|
||||
val /= 128;
|
||||
oid[i++] = (byte) (((tb++) ? 0x80 : 0) | x);
|
||||
}
|
||||
|
||||
if ((idx+(word32)i) > *outSz) {
|
||||
XFREE(str, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
return BUFFER_E;
|
||||
}
|
||||
|
||||
oid[i] = (byte) (((tb++) ? 0x80 : 0) | val);
|
||||
|
||||
/* push value in the right order */
|
||||
while (i >= 0)
|
||||
out[idx++] = oid[i--];
|
||||
}
|
||||
|
||||
token = XSTRTOK(NULL, ".", &ptr);
|
||||
nb_val++;
|
||||
}
|
||||
|
||||
*outSz = idx;
|
||||
|
||||
XFREE(str, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* encode Certificate Policies, return total bytes written
|
||||
* each input value must be ITU-T X.690 formatted : a.b.c...
|
||||
* input must be an array of values with a NULL terminated for the latest
|
||||
@ -13914,6 +13833,90 @@ int wc_SetDatesBuffer(Cert* cert, const byte* der, int derSz)
|
||||
|
||||
#endif /* WOLFSSL_CERT_GEN */
|
||||
|
||||
#if (defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT)) \
|
||||
|| defined(OPENSSL_EXTRA)
|
||||
/* Encode OID string representation to ITU-T X.690 format */
|
||||
int EncodePolicyOID(byte *out, word32 *outSz, const char *in, void* heap)
|
||||
{
|
||||
word32 val, idx = 0, nb_val;
|
||||
char *token, *str, *ptr;
|
||||
word32 len;
|
||||
|
||||
(void)heap;
|
||||
|
||||
if (out == NULL || outSz == NULL || *outSz < 2 || in == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
/* duplicate string (including terminator) */
|
||||
len = (word32)XSTRLEN(in);
|
||||
str = (char *)XMALLOC(len+1, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (str == NULL)
|
||||
return MEMORY_E;
|
||||
XMEMCPY(str, in, len+1);
|
||||
|
||||
nb_val = 0;
|
||||
|
||||
/* parse value, and set corresponding Policy OID value */
|
||||
token = XSTRTOK(str, ".", &ptr);
|
||||
while (token != NULL)
|
||||
{
|
||||
val = (word32)XATOI(token);
|
||||
|
||||
if (nb_val == 0) {
|
||||
if (val > 2) {
|
||||
XFREE(str, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
return ASN_OBJECT_ID_E;
|
||||
}
|
||||
|
||||
out[idx] = (byte)(40 * val);
|
||||
}
|
||||
else if (nb_val == 1) {
|
||||
if (val > 127) {
|
||||
XFREE(str, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
return ASN_OBJECT_ID_E;
|
||||
}
|
||||
|
||||
if (idx > *outSz) {
|
||||
XFREE(str, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
return BUFFER_E;
|
||||
}
|
||||
|
||||
out[idx++] += (byte)val;
|
||||
}
|
||||
else {
|
||||
word32 tb = 0, x;
|
||||
int i = 0;
|
||||
byte oid[MAX_OID_SZ];
|
||||
|
||||
while (val >= 128) {
|
||||
x = val % 128;
|
||||
val /= 128;
|
||||
oid[i++] = (byte) (((tb++) ? 0x80 : 0) | x);
|
||||
}
|
||||
|
||||
if ((idx+(word32)i) > *outSz) {
|
||||
XFREE(str, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
return BUFFER_E;
|
||||
}
|
||||
|
||||
oid[i] = (byte) (((tb++) ? 0x80 : 0) | val);
|
||||
|
||||
/* push value in the right order */
|
||||
while (i >= 0)
|
||||
out[idx++] = oid[i--];
|
||||
}
|
||||
|
||||
token = XSTRTOK(NULL, ".", &ptr);
|
||||
nb_val++;
|
||||
}
|
||||
|
||||
*outSz = idx;
|
||||
|
||||
XFREE(str, heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
return 0;
|
||||
}
|
||||
#endif /* WOLFSSL_CERT_EXT || OPENSSL_EXTRA */
|
||||
|
||||
#endif /* !NO_CERTS */
|
||||
|
||||
#ifdef HAVE_ECC
|
||||
|
@ -9247,7 +9247,8 @@ byte GetEntropy(ENTROPY_CMD cmd, byte* out)
|
||||
#endif /* HAVE_ECC */
|
||||
|
||||
#ifndef NO_RSA
|
||||
#if defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_CERT_EXT)
|
||||
#if defined(WOLFSSL_CERT_GEN) || \
|
||||
(defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT))
|
||||
static const char* otherCertDerFile = CERT_PREFIX "othercert.der";
|
||||
static const char* certDerFile = CERT_PREFIX "cert.der";
|
||||
#endif
|
||||
|
@ -528,7 +528,8 @@
|
||||
#define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
|
||||
#define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n))
|
||||
#define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n))
|
||||
#if defined(WOLFSSL_CERT_EXT) || defined(HAVE_ALPN)
|
||||
#if defined(WOLFSSL_CERT_EXT) || defined(OPENSSL_EXTRA) \
|
||||
|| defined(HAVE_ALPN)
|
||||
#define XSTRTOK strtok_r
|
||||
#endif
|
||||
#endif
|
||||
|
@ -493,7 +493,8 @@
|
||||
#endif /* _MSC_VER || __CYGWIN__ || __MINGW32__ */
|
||||
#endif /* USE_WINDOWS_API */
|
||||
|
||||
#if defined(WOLFSSL_CERT_EXT) || defined(HAVE_ALPN)
|
||||
#if defined(WOLFSSL_CERT_EXT) || defined(OPENSSL_EXTRA) \
|
||||
|| defined(HAVE_ALPN)
|
||||
/* use only Thread Safe version of strtok */
|
||||
#if defined(USE_WOLF_STRTOK)
|
||||
#define XSTRTOK(s1,d,ptr) wc_strtok((s1),(d),(ptr))
|
||||
|
Reference in New Issue
Block a user