Ignore:
Timestamp:
Jun 22, 2021, 9:00:19 PM (3 years ago)
Author:
coas-nagasima
Message:

WolfSSLとAzure IoT SDKを更新

Location:
azure_iot_hub_f767zi/trunk/wolfssl-4.7.0
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • azure_iot_hub_f767zi/trunk/wolfssl-4.7.0/wolfssl/wolfcrypt/asn.h

    r457 r464  
    2424*/
    2525
     26/*
     27
     28DESCRIPTION
     29This library provides the interface to Abstract Syntax Notation One (ASN.1) objects.
     30ASN.1 is a standard interface description language for defining data structures
     31that can be serialized and deserialized in a cross-platform way.
     32
     33*/
    2634#ifndef WOLF_CRYPT_ASN_H
    2735#define WOLF_CRYPT_ASN_H
     
    93101    ASN_SET               = 0x11,
    94102    ASN_PRINTABLE_STRING  = 0x13,
     103    ASN_IA5_STRING        = 0x16,
    95104    ASN_UTC_TIME          = 0x17,
    96105    ASN_OTHER_TYPE        = 0x00,
     
    134143    ASN_DOMAIN_COMPONENT = 0x19  /* DC */
    135144};
     145
     146/* This is the size of the smallest possible PEM header and footer */
     147extern const int pem_struct_min_sz;
    136148
    137149#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
     
    195207    NID_sha384 = 673,
    196208    NID_sha512 = 674,
     209    NID_pkcs9_challengePassword = 54,
    197210    NID_hw_name_oid = 73,
    198211    NID_id_pkix_OCSP_basic = 74,
     
    221234    NID_tlsfeature = 1020,             /* id-pe 24 */
    222235    NID_commonName = 0x03,             /* matches ASN_COMMON_NAME in asn.h */
     236    NID_buildingName = 1494,
    223237
    224238
     
    234248    NID_businessCategory = ASN_BUS_CAT,
    235249    NID_domainComponent = ASN_DOMAIN_COMPONENT,
     250    NID_userId = 458,
    236251    NID_emailAddress = 0x30,           /* emailAddress */
    237252    NID_id_on_dnsSRV = 82,             /* 1.3.6.1.5.5.7.8.7 */
     
    292307    RSA_INTS            =   8,     /* RSA ints in private key */
    293308    DSA_INTS            =   5,     /* DSA ints in private key */
    294     MIN_DATE_SIZE       =  13,
     309    MIN_DATE_SIZE       =  12,
    295310    MAX_DATE_SIZE       =  32,
    296311    ASN_GEN_TIME_SZ     =  15,     /* 7 numbers * 2 + Zulu tag */
     
    327342    MAX_DER_DIGEST_ASN_SZ = MAX_ENCODED_DIG_ASN_SZ + MAX_ALGO_SZ + MAX_SEQ_SZ,
    328343                            /* Maximum DER digest ASN header size */
     344                            /* Max X509 header length indicates the max length + 2 ('\n', '\0') */
     345    MAX_X509_HEADER_SZ  = (37 + 2), /* Maximum PEM Header/Footer Size */
    329346#ifdef WOLFSSL_CERT_GEN
    330347    #ifdef WOLFSSL_CERT_REQ
     
    340357                                   /* Max total extensions, id + len + others */
    341358#endif
    342 #if defined(WOLFSSL_CERT_EXT) || defined(OPENSSL_EXTRA) || defined(HAVE_PKCS7)
     359#if defined(WOLFSSL_CERT_EXT) || defined(OPENSSL_EXTRA) || \
     360        defined(HAVE_PKCS7) || defined(OPENSSL_EXTRA_X509_SMALL)
    343361    MAX_OID_SZ          = 32,      /* Max DER length of OID*/
    344362    MAX_OID_STRING_SZ   = 64,      /* Max string length representation of OID*/
     
    355373#endif
    356374    MAX_AIA_SZ          = 2,       /* Max Authority Info Access extension size*/
    357     MAX_NAME_ENTRIES    = 5,       /* extra entries added to x509 name struct */
    358375    OCSP_NONCE_EXT_SZ   = 35,      /* OCSP Nonce Extension size */
    359376    MAX_OCSP_EXT_SZ     = 58,      /* Max OCSP Extension length */
     
    370387    ASN_TAG_SZ          = 1,       /* single byte ASN.1 tag */
    371388    MIN_VERSION_SZ      = 3,       /* Min bytes needed for GetMyVersion */
     389    MAX_X509_VERSION    = 3,       /* Max X509 version allowed */
     390    MIN_X509_VERSION    = 0,       /* Min X509 version allowed */
     391    WOLFSSL_X509_V1     = 0,
     392    WOLFSSL_X509_V2     = 1,
     393    WOLFSSL_X509_V3     = 2,
    372394#if defined(OPENSSL_ALL)  || defined(WOLFSSL_MYSQL_COMPATIBLE) || \
    373395    defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \
     
    378400    PKCS5_SALT_SZ       = 8,
    379401
    380     PEM_LINE_LEN       = 80,       /* PEM line max + fudge */
    381 };
     402    PEM_LINE_SZ        = 64,               /* Length of Base64 encoded line, not including new line */
     403    PEM_LINE_LEN       = PEM_LINE_SZ + 12, /* PEM line max + fudge */
     404};
     405
     406#ifndef WC_MAX_NAME_ENTRIES
     407    /* entries added to x509 name struct */
     408    #define WC_MAX_NAME_ENTRIES 13
     409#endif
     410#define MAX_NAME_ENTRIES WC_MAX_NAME_ENTRIES
    382411
    383412
     
    403432    oidTlsExtType       = 18,
    404433    oidCrlExtType       = 19,
     434    oidCsrAttrType      = 20,
    405435    oidIgnoreType
    406436};
     
    519549    ISSUE_ALT_NAMES_OID       = 132,
    520550    TLS_FEATURE_OID           = 92,  /* id-pe 24 */
    521     NETSCAPE_CT_OID           = 753  /* 2.16.840.1.113730.1.1 */
     551    NETSCAPE_CT_OID           = 753, /* 2.16.840.1.113730.1.1 */
     552    OCSP_NOCHECK_OID          = 121  /* 1.3.6.1.5.5.7.48.1.5
     553                                         id-pkix-ocsp-nocheck */
    522554};
    523555
     
    564596    SKID_TYPE = 0,
    565597    AKID_TYPE = 1
     598};
     599#endif
     600
     601#ifdef WOLFSSL_CERT_REQ
     602enum CsrAttrType {
     603    CHALLENGE_PASSWORD_OID = 659,
     604    SERIAL_NUMBER_OID = 94,
     605    EXTENSION_REQUEST_OID = 666,
    566606};
    567607#endif
     
    607647};
    608648
    609 #define DOMAIN_COMPONENT_MAX 10
    610 #define DN_NAMES_MAX 9
    611 
    612 struct DecodedName {
    613     char*   fullName;
    614     int     fullNameLen;
    615     int     entryCount;
    616     int     cnIdx;
    617     int     cnLen;
    618     int     cnNid;
    619     int     snIdx;
    620     int     snLen;
    621     int     snNid;
    622     int     cIdx;
    623     int     cLen;
    624     int     cNid;
    625     int     lIdx;
    626     int     lLen;
    627     int     lNid;
    628     int     stIdx;
    629     int     stLen;
    630     int     stNid;
    631     int     oIdx;
    632     int     oLen;
    633     int     oNid;
    634     int     ouIdx;
    635     int     ouLen;
    636 #ifdef WOLFSSL_CERT_EXT
    637     int     bcIdx;
    638     int     bcLen;
    639     int     jcIdx;
    640     int     jcLen;
    641     int     jsIdx;
    642     int     jsLen;
    643 #endif
    644     int     ouNid;
    645     int     emailIdx;
    646     int     emailLen;
    647     int     emailNid;
    648     int     uidIdx;
    649     int     uidLen;
    650     int     uidNid;
    651     int     serialIdx;
    652     int     serialLen;
    653     int     serialNid;
    654     int     dcIdx[DOMAIN_COMPONENT_MAX];
    655     int     dcLen[DOMAIN_COMPONENT_MAX];
    656     int     dcNum;
    657     int     dcMode;
    658 #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
    659     /* hold the location / order with which each of the DN tags was found
    660      *
    661      * example of ASN_DOMAIN_COMPONENT at index 0 if first found and so on.
    662      */
    663     int     loc[DOMAIN_COMPONENT_MAX + DN_NAMES_MAX];
    664     int     locSz;
    665 #endif
    666 };
    667649
    668650enum SignatureState {
     
    697679#ifndef NO_RSA
    698680    byte* out;
    699     byte* plain;
    700 #endif
    701 #if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
     681#endif
     682#if !(defined(NO_RSA) && defined(NO_DSA))
     683    byte* sigCpy;
     684#endif
     685#if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448) || \
     686    !defined(NO_DSA)
    702687    int verify;
    703688#endif
     
    705690    #ifndef NO_RSA
    706691        struct RsaKey*      rsa;
     692    #endif
     693    #ifndef NO_DSA
     694        struct DsaKey*      dsa;
    707695    #endif
    708696    #ifdef HAVE_ECC
     
    782770
    783771typedef struct DecodedCert DecodedCert;
    784 typedef struct DecodedName DecodedName;
    785772typedef struct Signer      Signer;
    786773#ifdef WOLFSSL_TRUST_PEER_CERT
     
    804791#ifndef IGNORE_NAME_CONSTRAINTS
    805792    DNS_entry* altEmailNames;        /* alt names list of RFC822 entries */
     793    DNS_entry* altDirNames;          /* alt names list of DIR entries    */
    806794    Base_entry* permittedNames;      /* Permitted name bases             */
    807795    Base_entry* excludedNames;       /* Excluded name bases              */
     
    909897#endif /* WOLFSSL_CERT_GEN */
    910898#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
    911     DecodedName issuerName;
    912     DecodedName subjectName;
     899    /* WOLFSSL_X509_NAME structures (used void* to avoid including ssl.h) */
     900    void* issuerName;
     901    void* subjectName;
    913902#endif /* OPENSSL_EXTRA */
    914903#ifdef WOLFSSL_SEP
     
    925914#endif /* defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_CERT_EXT) */
    926915
     916#ifdef WOLFSSL_CERT_REQ
     917    /* CSR attributes */
     918    char*   cPwd; /* challengePassword */
     919    int     cPwdLen;
     920    char*   sNum; /* Serial Number */
     921    int     sNumLen;
     922#endif /* WOLFSSL_CERT_REQ */
     923
    927924    Signer* ca;
    928925#ifndef NO_CERTS
     
    948945    byte extKeyUsageSet : 1;
    949946    byte extExtKeyUsageSet : 1;    /* Extended Key Usage set */
     947#ifdef HAVE_OCSP
     948    byte ocspNoCheckSet : 1;       /* id-pkix-ocsp-nocheck set */
     949#endif
    950950    byte extCRLdistSet : 1;
    951951    byte extAuthInfoSet : 1;
     
    973973    byte extCertPolicyCrit : 1;
    974974#endif
    975 
     975#ifdef WOLFSSL_CERT_REQ
     976    byte isCSR : 1;                /* Do we intend on parsing a CSR? */
     977#endif
    976978};
    977979
     
    10491051#endif
    10501052
     1053#ifdef HAVE_SMIME
     1054#define MIME_HEADER_ASCII_MIN   33
     1055#define MIME_HEADER_ASCII_MAX   126
     1056
     1057typedef struct MimeParam MimeParam;
     1058typedef struct MimeHdr MimeHdr;
     1059
     1060struct MimeParam
     1061{
     1062    MimeParam*  next;
     1063    char*       attribute;
     1064    char*       value;
     1065};
     1066
     1067struct MimeHdr
     1068{
     1069    MimeHdr*    next;
     1070    MimeParam*  params;
     1071    char*       name;
     1072    char*       body;
     1073};
     1074
     1075typedef enum MimeTypes
     1076{
     1077    MIME_HDR,
     1078    MIME_PARAM
     1079} MimeTypes;
     1080
     1081typedef enum MimeStatus
     1082{
     1083    MIME_NAMEATTR,
     1084    MIME_BODYVAL
     1085} MimeStatus;
     1086#endif /* HAVE_SMIME */
     1087
     1088
    10511089WOLFSSL_LOCAL int CalcHashId(const byte* data, word32 len, byte* hash);
     1090WOLFSSL_LOCAL int GetName(DecodedCert* cert, int nameType, int maxIdx);
    10521091
    10531092WOLFSSL_ASN_API int wc_BerToDer(const byte* ber, word32 berSz, byte* der,
     
    10691108WOLFSSL_LOCAL int CheckCertSignaturePubKey(const byte* cert, word32 certSz,
    10701109        void* heap, const byte* pubKey, word32 pubKeySz, int pubKeyOID);
     1110#ifdef WOLFSSL_CERT_REQ
     1111WOLFSSL_LOCAL int CheckCSRSignaturePubKey(const byte* cert, word32 certSz, void* heap,
     1112        const byte* pubKey, word32 pubKeySz, int pubKeyOID);
     1113#endif /* WOLFSSL_CERT_REQ */
     1114WOLFSSL_LOCAL int AddSignature(byte* buf, int bodySz, const byte* sig, int sigSz,
     1115                        int sigAlgoType);
    10711116WOLFSSL_LOCAL int ParseCertRelative(DecodedCert*,int type,int verify,void* cm);
    10721117WOLFSSL_LOCAL int DecodeToKey(DecodedCert*, int verify);
     
    11161161                                                 wolfssl_tm* certTime, int* idx);
    11171162WOLFSSL_LOCAL int DateGreaterThan(const struct tm* a, const struct tm* b);
    1118 WOLFSSL_LOCAL int ValidateDate(const byte* date, byte format, int dateType);
     1163WOLFSSL_LOCAL int wc_ValidateDate(const byte* date, byte format, int dateType);
    11191164WOLFSSL_LOCAL int wc_OBJ_sn2nid(const char *sn);
    11201165
     
    11221167#ifdef WOLFSSL_CERT_GEN
    11231168WOLFSSL_ASN_API int SetName(byte* output, word32 outputSz, CertName* name);
     1169WOLFSSL_LOCAL const char* GetOneCertName(CertName* name, int idx);
     1170WOLFSSL_LOCAL byte GetCertNameId(int idx);
    11241171#endif
    11251172WOLFSSL_LOCAL int GetShortInt(const byte* input, word32* inOutIdx, int* number,
     
    11391186WOLFSSL_LOCAL int GetOctetString(const byte* input, word32* inOutIdx, int* len,
    11401187                         word32 maxIdx);
     1188WOLFSSL_LOCAL int CheckBitString(const byte* input, word32* inOutIdx, int* len,
     1189                          word32 maxIdx, int zeroBits, byte* unusedBits);
    11411190WOLFSSL_LOCAL int GetSet(const byte* input, word32* inOutIdx, int* len,
    11421191                        word32 maxIdx);
     
    11731222WOLFSSL_LOCAL int wc_DhPrivKeyToDer(DhKey* key, byte* out, word32* outSz);
    11741223#endif
     1224WOLFSSL_LOCAL int SetASNInt(int len, byte firstByte, byte* output);
    11751225WOLFSSL_LOCAL word32 SetBitString(word32 len, byte unusedBits, byte* output);
    11761226WOLFSSL_LOCAL word32 SetImplicit(byte tag,byte number,word32 len,byte* output);
     
    11851235WOLFSSL_LOCAL int GetNameHash(const byte* source, word32* idx, byte* hash,
    11861236                             int maxIdx);
    1187 WOLFSSL_LOCAL int wc_CheckPrivateKey(byte* key, word32 keySz, DecodedCert* der);
     1237WOLFSSL_LOCAL int wc_CheckPrivateKeyCert(const byte* key, word32 keySz, DecodedCert* der);
     1238WOLFSSL_LOCAL int wc_CheckPrivateKey(const byte* privKey, word32 privKeySz,
     1239                                     const byte* pubKey, word32 pubKeySz, enum Key_Sum ks);
    11881240WOLFSSL_LOCAL int StoreDHparams(byte* out, word32* outLen, mp_int* p, mp_int* g);
    11891241WOLFSSL_LOCAL int FlattenAltNames( byte*, word32, const DNS_entry*);
     
    11931245    WOLFSSL_LOCAL int StoreECC_DSA_Sig(byte* out, word32* outLen, mp_int* r,
    11941246                                      mp_int* s);
     1247    WOLFSSL_LOCAL int StoreECC_DSA_Sig_Bin(byte* out, word32* outLen,
     1248        const byte* r, word32 rLen, const byte* s, word32 sLen);
     1249    WOLFSSL_LOCAL int DecodeECC_DSA_Sig_Bin(const byte* sig, word32 sigLen,
     1250        byte* r, word32* rLen, byte* s, word32* sLen);
     1251#endif
     1252#if defined(HAVE_ECC) || !defined(NO_DSA)
    11951253    WOLFSSL_LOCAL int DecodeECC_DSA_Sig(const byte* sig, word32 sigLen,
    11961254                                       mp_int* r, mp_int* s);
     
    12151273
    12161274#endif /* !NO_CERTS */
     1275
     1276#ifdef HAVE_SMIME
     1277WOLFSSL_LOCAL int wc_MIME_parse_headers(char* in, int inLen, MimeHdr** hdrs);
     1278WOLFSSL_LOCAL int wc_MIME_header_strip(char* in, char** out, size_t start, size_t end);
     1279WOLFSSL_LOCAL int wc_MIME_create_header(char* name, char* body, MimeHdr** hdr);
     1280WOLFSSL_LOCAL int wc_MIME_create_parameter(char* attribute, char* value, MimeParam** param);
     1281WOLFSSL_LOCAL MimeHdr* wc_MIME_find_header_name(const char* name, MimeHdr* hdr);
     1282WOLFSSL_LOCAL MimeParam* wc_MIME_find_param_attr(const char* attribute, MimeParam* param);
     1283WOLFSSL_LOCAL int wc_MIME_free_hdrs(MimeHdr* head);
     1284#endif /* HAVE_SMIME */
    12171285
    12181286#ifdef WOLFSSL_CERT_GEN
     
    12311299    ECC_KEY         = 12,
    12321300    ED25519_KEY     = 13,
    1233     ED448_KEY       = 14
     1301    ED448_KEY       = 14,
     1302    DSA_KEY         = 15
    12341303};
    12351304
     
    12821351    byte serial[EXTERNAL_SERIAL_SIZE];
    12831352    int serialSz;
     1353#ifdef OPENSSL_EXTRA
     1354    WOLFSSL_ASN1_INTEGER* serialInt;
     1355#endif
    12841356
    12851357    int status;
     
    12891361    byte thisDateFormat;
    12901362    byte nextDateFormat;
    1291 #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
     1363#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)
    12921364    WOLFSSL_ASN1_TIME thisDateParsed;
    12931365    WOLFSSL_ASN1_TIME nextDateParsed;
     
    13001372};
    13011373
    1302 
     1374typedef struct OcspEntry OcspEntry;
     1375
     1376#ifdef NO_SHA
     1377#define OCSP_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
     1378#else
     1379#define OCSP_DIGEST_SIZE WC_SHA_DIGEST_SIZE
     1380#endif
     1381
     1382struct OcspEntry
     1383{
     1384    OcspEntry *next;                      /* next entry                */
     1385    word32 hashAlgoOID;                   /* hash algo ID              */
     1386    byte issuerHash[OCSP_DIGEST_SIZE];    /* issuer hash               */
     1387    byte issuerKeyHash[OCSP_DIGEST_SIZE]; /* issuer public key hash    */
     1388    CertStatus *status;                   /* OCSP response list        */
     1389    int totalStatus;                      /* number on list            */
     1390    byte* rawCertId;                      /* raw bytes of the CertID   */
     1391    int rawCertIdSize;                    /* num bytes in raw CertID   */
     1392    /* option bits - using 32-bit for alignment */
     1393    word32 isDynamic:1;                   /* was dynamically allocated */
     1394
     1395};
     1396
     1397/* TODO: Long-term, it would be helpful if we made this struct and other OCSP
     1398         structs conform to the ASN spec as described in RFC 6960. It will help
     1399         with readability and with implementing OpenSSL compatibility API
     1400         functions, because OpenSSL's OCSP data structures conform to the
     1401         RFC. */
    13031402struct OcspResponse {
    13041403    int     responseStatus;  /* return code from Responder */
     
    13101409                             /* Date at which this response was signed */
    13111410    byte    producedDateFormat; /* format of the producedDate */
    1312     byte*   issuerHash;
    1313     byte*   issuerKeyHash;
    13141411
    13151412    byte*   cert;
     
    13201417    word32  sigOID;          /* OID for hash used for sig */
    13211418
    1322     CertStatus* status;      /* certificate status to fill out */
     1419    OcspEntry* single;       /* chain of OCSP single responses */
    13231420
    13241421    byte*   nonce;           /* pointer to nonce inside ASN.1 response */
     
    13311428    int     verifyError;
    13321429#endif
     1430    void*  heap;
    13331431};
    13341432
     
    13511449};
    13521450
    1353 typedef struct OcspEntry OcspEntry;
    1354 
    1355 #ifdef NO_SHA
    1356 #define OCSP_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
    1357 #else
    1358 #define OCSP_DIGEST_SIZE WC_SHA_DIGEST_SIZE
    1359 #endif
    1360 
    1361 struct OcspEntry
    1362 {
    1363     OcspEntry *next;                      /* next entry             */
    1364     byte issuerHash[OCSP_DIGEST_SIZE];    /* issuer hash            */
    1365     byte issuerKeyHash[OCSP_DIGEST_SIZE]; /* issuer public key hash */
    1366     CertStatus *status;                   /* OCSP response list     */
    1367     int totalStatus;                      /* number on list         */
    1368 };
    1369 
    1370 WOLFSSL_LOCAL void InitOcspResponse(OcspResponse*, CertStatus*, byte*, word32);
    1371 WOLFSSL_LOCAL int  OcspResponseDecode(OcspResponse*, void*, void* heap, int);
     1451WOLFSSL_LOCAL void InitOcspResponse(OcspResponse*, OcspEntry*, CertStatus*, byte*, word32, void*);
     1452WOLFSSL_LOCAL void FreeOcspResponse(OcspResponse*);
     1453WOLFSSL_LOCAL int OcspResponseDecode(OcspResponse*, void*, void* heap, int);
    13721454
    13731455WOLFSSL_LOCAL int    InitOcspRequest(OcspRequest*, DecodedCert*, byte, void*);
     
    14471529
    14481530enum PBESTypes {
    1449     PBE_MD5_DES      = 0,
    1450     PBE_SHA1_RC4_128 = 1,
    1451     PBE_SHA1_DES     = 2,
    1452     PBE_SHA1_DES3    = 3,
    1453     PBE_AES256_CBC   = 4,
    1454     PBE_AES128_CBC   = 5,
     1531    PBE_MD5_DES        = 0,
     1532    PBE_SHA1_RC4_128   = 1,
     1533    PBE_SHA1_DES       = 2,
     1534    PBE_SHA1_DES3      = 3,
     1535    PBE_AES256_CBC     = 4,
     1536    PBE_AES128_CBC     = 5,
     1537    PBE_SHA1_40RC2_CBC = 6,
    14551538
    14561539    PBE_SHA1_RC4_128_SUM = 657,
Note: See TracChangeset for help on using the changeset viewer.