| OLD | NEW |
| 1 /* alg1485.c - implementation of RFCs 1485, 1779 and 2253. | 1 /* alg1485.c - implementation of RFCs 1485, 1779 and 2253. |
| 2 * | 2 * |
| 3 * This Source Code Form is subject to the terms of the Mozilla Public | 3 * This Source Code Form is subject to the terms of the Mozilla Public |
| 4 * License, v. 2.0. If a copy of the MPL was not distributed with this | 4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 | 6 |
| 7 #include "prprf.h" | 7 #include "prprf.h" |
| 8 #include "cert.h" | 8 #include "cert.h" |
| 9 #include "certi.h" | 9 #include "certi.h" |
| 10 #include "xconst.h" | 10 #include "xconst.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 /* values defined by the CAB Forum for EV */ | 77 /* values defined by the CAB Forum for EV */ |
| 78 { "incorporationLocality", 128, SEC_OID_EV_INCORPORATION_LOCALITY, | 78 { "incorporationLocality", 128, SEC_OID_EV_INCORPORATION_LOCALITY, |
| 79 SEC_ASN1_DS}, | 79 SEC_ASN1_DS}, |
| 80 { "incorporationState", 128, SEC_OID_EV_INCORPORATION_STATE, | 80 { "incorporationState", 128, SEC_OID_EV_INCORPORATION_STATE, |
| 81 SEC_ASN1_DS}, | 81 SEC_ASN1_DS}, |
| 82 { "incorporationCountry", 2, SEC_OID_EV_INCORPORATION_COUNTRY, | 82 { "incorporationCountry", 2, SEC_OID_EV_INCORPORATION_COUNTRY, |
| 83 SEC_ASN1_PRINTABLE_STRING}, | 83 SEC_ASN1_PRINTABLE_STRING}, |
| 84 { "businessCategory", 64, SEC_OID_BUSINESS_CATEGORY, SEC_ASN1_DS}, | 84 { "businessCategory", 64, SEC_OID_BUSINESS_CATEGORY, SEC_ASN1_DS}, |
| 85 | 85 |
| 86 /* values defined in X.520 */ |
| 87 { "name", 64, SEC_OID_AVA_NAME, SEC_ASN1_DS}, |
| 88 |
| 86 { 0, 256, SEC_OID_UNKNOWN, 0}, | 89 { 0, 256, SEC_OID_UNKNOWN, 0}, |
| 87 }; | 90 }; |
| 88 | 91 |
| 89 /* Table facilitates conversion of ASCII hex to binary. */ | 92 /* Table facilitates conversion of ASCII hex to binary. */ |
| 90 static const PRInt16 x2b[256] = { | 93 static const PRInt16 x2b[256] = { |
| 91 /* #0x */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | 94 /* #0x */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 92 /* #1x */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | 95 /* #1x */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 93 /* #2x */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | 96 /* #2x */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 94 /* #3x */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, | 97 /* #3x */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, |
| 95 /* #4x */ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, | 98 /* #4x */ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| (...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 } | 1191 } |
| 1189 } | 1192 } |
| 1190 SECITEM_FreeItem(avaValue, PR_TRUE); | 1193 SECITEM_FreeItem(avaValue, PR_TRUE); |
| 1191 return buf; | 1194 return buf; |
| 1192 } | 1195 } |
| 1193 | 1196 |
| 1194 /* RDNs are sorted from most general to most specific. | 1197 /* RDNs are sorted from most general to most specific. |
| 1195 * This code returns the FIRST one found, the most general one found. | 1198 * This code returns the FIRST one found, the most general one found. |
| 1196 */ | 1199 */ |
| 1197 static char * | 1200 static char * |
| 1198 CERT_GetNameElement(PRArenaPool *arena, CERTName *name, int wantedTag) | 1201 CERT_GetNameElement(PRArenaPool *arena, const CERTName *name, int wantedTag) |
| 1199 { | 1202 { |
| 1200 CERTRDN** rdns = name->rdns; | 1203 CERTRDN** rdns = name->rdns; |
| 1201 CERTRDN* rdn; | 1204 CERTRDN* rdn; |
| 1202 CERTAVA* ava = NULL; | 1205 CERTAVA* ava = NULL; |
| 1203 | 1206 |
| 1204 while (rdns && (rdn = *rdns++) != 0) { | 1207 while (rdns && (rdn = *rdns++) != 0) { |
| 1205 CERTAVA** avas = rdn->avas; | 1208 CERTAVA** avas = rdn->avas; |
| 1206 while (avas && (ava = *avas++) != 0) { | 1209 while (avas && (ava = *avas++) != 0) { |
| 1207 int tag = CERT_GetAVATag(ava); | 1210 int tag = CERT_GetAVATag(ava); |
| 1208 if ( tag == wantedTag ) { | 1211 if ( tag == wantedTag ) { |
| 1209 avas = NULL; | 1212 avas = NULL; |
| 1210 rdns = NULL; /* break out of all loops */ | 1213 rdns = NULL; /* break out of all loops */ |
| 1211 } | 1214 } |
| 1212 } | 1215 } |
| 1213 } | 1216 } |
| 1214 return ava ? avaToString(arena, ava) : NULL; | 1217 return ava ? avaToString(arena, ava) : NULL; |
| 1215 } | 1218 } |
| 1216 | 1219 |
| 1217 /* RDNs are sorted from most general to most specific. | 1220 /* RDNs are sorted from most general to most specific. |
| 1218 * This code returns the LAST one found, the most specific one found. | 1221 * This code returns the LAST one found, the most specific one found. |
| 1219 * This is particularly appropriate for Common Name. See RFC 2818. | 1222 * This is particularly appropriate for Common Name. See RFC 2818. |
| 1220 */ | 1223 */ |
| 1221 static char * | 1224 static char * |
| 1222 CERT_GetLastNameElement(PRArenaPool *arena, CERTName *name, int wantedTag) | 1225 CERT_GetLastNameElement(PRArenaPool *arena, const CERTName *name, int wantedTag) |
| 1223 { | 1226 { |
| 1224 CERTRDN** rdns = name->rdns; | 1227 CERTRDN** rdns = name->rdns; |
| 1225 CERTRDN* rdn; | 1228 CERTRDN* rdn; |
| 1226 CERTAVA* lastAva = NULL; | 1229 CERTAVA* lastAva = NULL; |
| 1227 | 1230 |
| 1228 while (rdns && (rdn = *rdns++) != 0) { | 1231 while (rdns && (rdn = *rdns++) != 0) { |
| 1229 CERTAVA** avas = rdn->avas; | 1232 CERTAVA** avas = rdn->avas; |
| 1230 CERTAVA* ava; | 1233 CERTAVA* ava; |
| 1231 while (avas && (ava = *avas++) != 0) { | 1234 while (avas && (ava = *avas++) != 0) { |
| 1232 int tag = CERT_GetAVATag(ava); | 1235 int tag = CERT_GetAVATag(ava); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1474 return prev; | 1477 return prev; |
| 1475 } | 1478 } |
| 1476 return NULL; | 1479 return NULL; |
| 1477 } | 1480 } |
| 1478 | 1481 |
| 1479 /* This is seriously bogus, now that certs store their email addresses in | 1482 /* This is seriously bogus, now that certs store their email addresses in |
| 1480 ** subject Alternative Name extensions. | 1483 ** subject Alternative Name extensions. |
| 1481 ** Returns a string allocated by PORT_StrDup, which the caller must free. | 1484 ** Returns a string allocated by PORT_StrDup, which the caller must free. |
| 1482 */ | 1485 */ |
| 1483 char * | 1486 char * |
| 1484 CERT_GetCertEmailAddress(CERTName *name) | 1487 CERT_GetCertEmailAddress(const CERTName *name) |
| 1485 { | 1488 { |
| 1486 char *rawEmailAddr; | 1489 char *rawEmailAddr; |
| 1487 char *emailAddr; | 1490 char *emailAddr; |
| 1488 | 1491 |
| 1489 | 1492 |
| 1490 rawEmailAddr = CERT_GetNameElement(NULL, name, SEC_OID_PKCS9_EMAIL_ADDRESS); | 1493 rawEmailAddr = CERT_GetNameElement(NULL, name, SEC_OID_PKCS9_EMAIL_ADDRESS); |
| 1491 if ( rawEmailAddr == NULL ) { | 1494 if ( rawEmailAddr == NULL ) { |
| 1492 rawEmailAddr = CERT_GetNameElement(NULL, name, SEC_OID_RFC1274_MAIL); | 1495 rawEmailAddr = CERT_GetNameElement(NULL, name, SEC_OID_RFC1274_MAIL); |
| 1493 } | 1496 } |
| 1494 emailAddr = CERT_FixupEmailAddr(rawEmailAddr); | 1497 emailAddr = CERT_FixupEmailAddr(rawEmailAddr); |
| 1495 if ( rawEmailAddr ) { | 1498 if ( rawEmailAddr ) { |
| 1496 PORT_Free(rawEmailAddr); | 1499 PORT_Free(rawEmailAddr); |
| 1497 } | 1500 } |
| 1498 return(emailAddr); | 1501 return(emailAddr); |
| 1499 } | 1502 } |
| 1500 | 1503 |
| 1501 /* The return value must be freed with PORT_Free. */ | 1504 /* The return value must be freed with PORT_Free. */ |
| 1502 char * | 1505 char * |
| 1503 CERT_GetCommonName(CERTName *name) | 1506 CERT_GetCommonName(const CERTName *name) |
| 1504 { | 1507 { |
| 1505 return(CERT_GetLastNameElement(NULL, name, SEC_OID_AVA_COMMON_NAME)); | 1508 return(CERT_GetLastNameElement(NULL, name, SEC_OID_AVA_COMMON_NAME)); |
| 1506 } | 1509 } |
| 1507 | 1510 |
| 1508 char * | 1511 char * |
| 1509 CERT_GetCountryName(CERTName *name) | 1512 CERT_GetCountryName(const CERTName *name) |
| 1510 { | 1513 { |
| 1511 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_COUNTRY_NAME)); | 1514 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_COUNTRY_NAME)); |
| 1512 } | 1515 } |
| 1513 | 1516 |
| 1514 char * | 1517 char * |
| 1515 CERT_GetLocalityName(CERTName *name) | 1518 CERT_GetLocalityName(const CERTName *name) |
| 1516 { | 1519 { |
| 1517 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_LOCALITY)); | 1520 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_LOCALITY)); |
| 1518 } | 1521 } |
| 1519 | 1522 |
| 1520 char * | 1523 char * |
| 1521 CERT_GetStateName(CERTName *name) | 1524 CERT_GetStateName(const CERTName *name) |
| 1522 { | 1525 { |
| 1523 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_STATE_OR_PROVINCE)); | 1526 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_STATE_OR_PROVINCE)); |
| 1524 } | 1527 } |
| 1525 | 1528 |
| 1526 char * | 1529 char * |
| 1527 CERT_GetOrgName(CERTName *name) | 1530 CERT_GetOrgName(const CERTName *name) |
| 1528 { | 1531 { |
| 1529 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_ORGANIZATION_NAME)); | 1532 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_ORGANIZATION_NAME)); |
| 1530 } | 1533 } |
| 1531 | 1534 |
| 1532 char * | 1535 char * |
| 1533 CERT_GetDomainComponentName(CERTName *name) | 1536 CERT_GetDomainComponentName(const CERTName *name) |
| 1534 { | 1537 { |
| 1535 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_DC)); | 1538 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_DC)); |
| 1536 } | 1539 } |
| 1537 | 1540 |
| 1538 char * | 1541 char * |
| 1539 CERT_GetOrgUnitName(CERTName *name) | 1542 CERT_GetOrgUnitName(const CERTName *name) |
| 1540 { | 1543 { |
| 1541 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_ORGANIZATIONAL_UNIT_NAME)
); | 1544 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_ORGANIZATIONAL_UNIT_NAME)
); |
| 1542 } | 1545 } |
| 1543 | 1546 |
| 1544 char * | 1547 char * |
| 1545 CERT_GetDnQualifier(CERTName *name) | 1548 CERT_GetDnQualifier(const CERTName *name) |
| 1546 { | 1549 { |
| 1547 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_DN_QUALIFIER)); | 1550 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_DN_QUALIFIER)); |
| 1548 } | 1551 } |
| 1549 | 1552 |
| 1550 char * | 1553 char * |
| 1551 CERT_GetCertUid(CERTName *name) | 1554 CERT_GetCertUid(const CERTName *name) |
| 1552 { | 1555 { |
| 1553 return(CERT_GetNameElement(NULL, name, SEC_OID_RFC1274_UID)); | 1556 return(CERT_GetNameElement(NULL, name, SEC_OID_RFC1274_UID)); |
| 1554 } | 1557 } |
| 1555 | 1558 |
| OLD | NEW |