implement wolfSSL_OBJ_txt2nid for OIDs

This commit is contained in:
Jacob Barthelmeh
2019-03-04 09:44:20 -07:00
parent 72f3329faa
commit 494e469dd2
3 changed files with 53 additions and 6 deletions

View File

@@ -32250,15 +32250,60 @@ void* wolfSSL_GetDhAgreeCtx(WOLFSSL* ssl)
}
#endif
#ifndef NO_WOLFSSL_STUB
/* Gets the NID value that is related to the OID string passed in. Example
* string would be "2.5.29.14" for subject key ID.
*
* @TODO does not handle short names yet
*
* returns NID value on success and NID_undef on error
*/
int wolfSSL_OBJ_txt2nid(const char* s)
{
(void)s;
WOLFSSL_STUB("OBJ_txt2nid");
int ret;
unsigned int outSz = 0;
unsigned char out[MAX_OID_SZ];
return 0;
WOLFSSL_ENTER("OBJ_txt2nid");
if (s == NULL) {
return NID_undef;
}
ret = EncodePolicyOID(out, &outSz, s, NULL);
if (ret == 0) {
unsigned int i, sum = 0;
int nid, grp = -1;
/* sum OID */
for (i = 0; i < outSz; i++) {
sum += out[i];
}
/* get the group that the OID's sum is in
* @TODO possible conflict with multiples */
for (i = 0; i < WOLFSSL_OBJECT_INFO_SZ; i++) {
if (wolfssl_object_info[i].id == (int)sum) {
grp = wolfssl_object_info[i].type;
}
}
if (grp == -1) {
WOLFSSL_MSG("OID sum's group was not found");
return NID_undef;
}
/* success return nid */
nid = oid2nid(sum, grp);
if (nid < 0) {
WOLFSSL_MSG("OID 2 NID function failed");
return NID_undef;
}
return nid;
}
else {
return 0;
}
}
#endif
/* compatibility function. It's intended use is to remove OID's from an
* internal table that have been added with OBJ_create. wolfSSL manages it's

View File

@@ -10847,7 +10847,7 @@ static int SetExtKeyUsage(Cert* cert, byte* output, word32 outSz, byte input)
}
/* Encode OID string representation to ITU-T X.690 format */
static int EncodePolicyOID(byte *out, word32 *outSz, const char *in, void* heap)
int EncodePolicyOID(byte *out, word32 *outSz, const char *in, void* heap)
{
word32 val, idx = 0, nb_val;
char *token, *str, *ptr;

View File

@@ -939,6 +939,8 @@ WOLFSSL_ASN_API int ParseCert(DecodedCert*, int type, int verify, void* cm);
WOLFSSL_LOCAL int DecodePolicyOID(char *o, word32 oSz,
const byte *in, word32 inSz);
WOLFSSL_LOCAL int EncodePolicyOID(byte *out, word32 *outSz,
const char *in, void* heap);
WOLFSSL_API int CheckCertSignature(const byte*,word32,void*,void* cm);
WOLFSSL_LOCAL int CheckCertSignaturePubKey(const byte* cert, word32 certSz,
void* heap, const byte* pubKey, word32 pubKeySz, int pubKeyOID);