1*46439007SCharles.Forsyth# 2*46439007SCharles.Forsyth# X.509 v3 by ITU-T Recommendation (11/93) & PKCS7 & PKCS10 3*46439007SCharles.Forsyth# 4*46439007SCharles.Forsyth 5*46439007SCharles.ForsythX509: module { 6*46439007SCharles.Forsyth 7*46439007SCharles.Forsyth PATH: con "/dis/lib/crypt/x509.dis"; 8*46439007SCharles.Forsyth 9*46439007SCharles.Forsyth init: fn(): string; 10*46439007SCharles.Forsyth 11*46439007SCharles.Forsyth ## x509 (id_at) and x509 extention v3 (id_ce) Object Identifiers 12*46439007SCharles.Forsyth 13*46439007SCharles.Forsyth objIdTab : array of ASN1->Oid; 14*46439007SCharles.Forsyth 15*46439007SCharles.Forsyth id_at, 16*46439007SCharles.Forsyth id_at_commonName, 17*46439007SCharles.Forsyth id_at_countryName, 18*46439007SCharles.Forsyth id_at_localityName, 19*46439007SCharles.Forsyth id_at_stateOrProvinceName, 20*46439007SCharles.Forsyth id_at_organizationName, 21*46439007SCharles.Forsyth id_at_organizationalUnitName, 22*46439007SCharles.Forsyth id_at_userPassword, 23*46439007SCharles.Forsyth id_at_userCertificate, 24*46439007SCharles.Forsyth id_at_cAcertificate, 25*46439007SCharles.Forsyth id_at_authorityRevocationList, 26*46439007SCharles.Forsyth id_at_certificateRevocationList, 27*46439007SCharles.Forsyth id_at_crossCertificatePair, 28*46439007SCharles.Forsyth id_at_supportedAlgorithms, 29*46439007SCharles.Forsyth id_at_deltaRevocationList, 30*46439007SCharles.Forsyth id_ce, 31*46439007SCharles.Forsyth id_ce_subjectDirectoryAttributes, 32*46439007SCharles.Forsyth id_ce_subjectKeyIdentifier, 33*46439007SCharles.Forsyth id_ce_keyUsage, 34*46439007SCharles.Forsyth id_ce_privateKeyUsage, 35*46439007SCharles.Forsyth id_ce_subjectAltName, 36*46439007SCharles.Forsyth id_ce_issuerAltName, 37*46439007SCharles.Forsyth id_ce_basicConstraints, 38*46439007SCharles.Forsyth id_ce_cRLNumber, 39*46439007SCharles.Forsyth id_ce_reasonCode, 40*46439007SCharles.Forsyth id_ce_instructionCode, 41*46439007SCharles.Forsyth id_ce_invalidityDate, 42*46439007SCharles.Forsyth id_ce_deltaCRLIndicator, 43*46439007SCharles.Forsyth id_ce_issuingDistributionPoint, 44*46439007SCharles.Forsyth id_ce_certificateIssuer, 45*46439007SCharles.Forsyth id_ce_nameConstraints, 46*46439007SCharles.Forsyth id_ce_cRLDistributionPoint, 47*46439007SCharles.Forsyth id_ce_certificatePolicies, 48*46439007SCharles.Forsyth id_ce_policyMapping, 49*46439007SCharles.Forsyth id_ce_authorityKeyIdentifier, 50*46439007SCharles.Forsyth id_ce_policyConstraints, 51*46439007SCharles.Forsyth id_mr, 52*46439007SCharles.Forsyth id_mr_certificateExactMatch, 53*46439007SCharles.Forsyth id_mr_certificateMatch, 54*46439007SCharles.Forsyth id_mr_certificatePairExactMatch, 55*46439007SCharles.Forsyth id_mr_certificatePairMatch, 56*46439007SCharles.Forsyth id_mr_certificateListExactMatch, 57*46439007SCharles.Forsyth id_mr_certificateListMatch, 58*46439007SCharles.Forsyth id_mr_algorithmidentifierMatch : con iota; 59*46439007SCharles.Forsyth 60*46439007SCharles.Forsyth ## Signed (as Public Key, CRL, Attribute Certificates and CertificationRequest) 61*46439007SCharles.Forsyth 62*46439007SCharles.Forsyth Signed: adt { 63*46439007SCharles.Forsyth tobe_signed : array of byte; 64*46439007SCharles.Forsyth alg : ref AlgIdentifier; 65*46439007SCharles.Forsyth signature : array of byte; # BIT STRING, DER encoding 66*46439007SCharles.Forsyth 67*46439007SCharles.Forsyth decode: fn(a: array of byte): (string, ref Signed); 68*46439007SCharles.Forsyth encode: fn(s: self ref Signed): (string, array of byte); 69*46439007SCharles.Forsyth sign: fn(s: self ref Signed, sk: ref PrivateKey, hash: int): (string, array of byte); 70*46439007SCharles.Forsyth verify: fn(s: self ref Signed, pk: ref PublicKey, hash: int): int; 71*46439007SCharles.Forsyth tostring: fn(s: self ref Signed): string; 72*46439007SCharles.Forsyth }; 73*46439007SCharles.Forsyth 74*46439007SCharles.Forsyth ## Certificate Path 75*46439007SCharles.Forsyth 76*46439007SCharles.Forsyth verify_certchain: fn(cs: list of array of byte): (int, string); 77*46439007SCharles.Forsyth verify_certpath: fn(cp: list of (ref Signed, ref Certificate)): (int, string); 78*46439007SCharles.Forsyth 79*46439007SCharles.Forsyth ## TBS (Public Key) Certificate 80*46439007SCharles.Forsyth 81*46439007SCharles.Forsyth Certificate: adt { 82*46439007SCharles.Forsyth version : int; # v1(0; default) or v2(1) or v3(2) 83*46439007SCharles.Forsyth serial_number : ref Keyring->IPint; 84*46439007SCharles.Forsyth sig : ref AlgIdentifier; 85*46439007SCharles.Forsyth issuer : ref Name; 86*46439007SCharles.Forsyth validity : ref Validity; 87*46439007SCharles.Forsyth subject : ref Name; 88*46439007SCharles.Forsyth subject_pkinfo : ref SubjectPKInfo; 89*46439007SCharles.Forsyth # OPTIONAL for v2 and v3; must be in order 90*46439007SCharles.Forsyth issuer_uid : array of byte; # v2 91*46439007SCharles.Forsyth subject_uid : array of byte; # v2 or v3 92*46439007SCharles.Forsyth exts : list of ref Extension; # v3 93*46439007SCharles.Forsyth 94*46439007SCharles.Forsyth decode: fn(a: array of byte): (string, ref Certificate); 95*46439007SCharles.Forsyth encode: fn(c: self ref Certificate): (string, array of byte); 96*46439007SCharles.Forsyth tostring: fn(c: self ref Certificate): string; 97*46439007SCharles.Forsyth is_expired: fn(c: self ref Certificate, date: int): int; 98*46439007SCharles.Forsyth }; 99*46439007SCharles.Forsyth 100*46439007SCharles.Forsyth AlgIdentifier: adt { 101*46439007SCharles.Forsyth oid : ref ASN1->Oid; 102*46439007SCharles.Forsyth parameter : array of byte; 103*46439007SCharles.Forsyth 104*46439007SCharles.Forsyth tostring: fn(a: self ref AlgIdentifier): string; 105*46439007SCharles.Forsyth }; 106*46439007SCharles.Forsyth 107*46439007SCharles.Forsyth Name: adt { 108*46439007SCharles.Forsyth rd_names : list of ref RDName; 109*46439007SCharles.Forsyth 110*46439007SCharles.Forsyth equal: fn(a: self ref Name, b: ref Name): int; 111*46439007SCharles.Forsyth tostring: fn(n: self ref Name): string; 112*46439007SCharles.Forsyth }; 113*46439007SCharles.Forsyth 114*46439007SCharles.Forsyth RDName: adt { 115*46439007SCharles.Forsyth avas : list of ref AVA; 116*46439007SCharles.Forsyth 117*46439007SCharles.Forsyth equal: fn(a: self ref RDName, b: ref RDName): int; 118*46439007SCharles.Forsyth tostring: fn(r: self ref RDName): string; 119*46439007SCharles.Forsyth }; 120*46439007SCharles.Forsyth 121*46439007SCharles.Forsyth AVA: adt { 122*46439007SCharles.Forsyth oid : ref ASN1->Oid; 123*46439007SCharles.Forsyth value : string; 124*46439007SCharles.Forsyth 125*46439007SCharles.Forsyth equal: fn(a: self ref AVA, b: ref AVA): int; 126*46439007SCharles.Forsyth tostring: fn(a: self ref AVA): string; 127*46439007SCharles.Forsyth }; 128*46439007SCharles.Forsyth 129*46439007SCharles.Forsyth Validity: adt { 130*46439007SCharles.Forsyth not_before : int; 131*46439007SCharles.Forsyth not_after : int; 132*46439007SCharles.Forsyth 133*46439007SCharles.Forsyth tostring: fn(v: self ref Validity, format: string): string; 134*46439007SCharles.Forsyth }; 135*46439007SCharles.Forsyth 136*46439007SCharles.Forsyth SubjectPKInfo: adt { 137*46439007SCharles.Forsyth alg_id : ref AlgIdentifier; 138*46439007SCharles.Forsyth subject_pk : array of byte; # BIT STRING 139*46439007SCharles.Forsyth 140*46439007SCharles.Forsyth getPublicKey: fn(c: self ref SubjectPKInfo): (string, int, ref PublicKey); 141*46439007SCharles.Forsyth tostring: fn(c: self ref SubjectPKInfo): string; 142*46439007SCharles.Forsyth }; 143*46439007SCharles.Forsyth 144*46439007SCharles.Forsyth Extension: adt{ 145*46439007SCharles.Forsyth oid : ref ASN1->Oid; 146*46439007SCharles.Forsyth critical : int; # default false 147*46439007SCharles.Forsyth value : array of byte; 148*46439007SCharles.Forsyth 149*46439007SCharles.Forsyth tostring: fn(e: self ref Extension): string; 150*46439007SCharles.Forsyth }; 151*46439007SCharles.Forsyth 152*46439007SCharles.Forsyth PublicKey: adt { 153*46439007SCharles.Forsyth pick { 154*46439007SCharles.Forsyth RSA => 155*46439007SCharles.Forsyth pk : ref PKCS->RSAKey; 156*46439007SCharles.Forsyth DSS => 157*46439007SCharles.Forsyth pk : ref PKCS->DSSPublicKey; 158*46439007SCharles.Forsyth DH => 159*46439007SCharles.Forsyth pk : ref PKCS->DHPublicKey; 160*46439007SCharles.Forsyth } 161*46439007SCharles.Forsyth }; 162*46439007SCharles.Forsyth 163*46439007SCharles.Forsyth PrivateKey: adt { 164*46439007SCharles.Forsyth pick { 165*46439007SCharles.Forsyth RSA => 166*46439007SCharles.Forsyth sk : ref PKCS->RSAKey; 167*46439007SCharles.Forsyth DSS => 168*46439007SCharles.Forsyth sk : ref PKCS->DSSPrivateKey; 169*46439007SCharles.Forsyth DH => 170*46439007SCharles.Forsyth sk : ref PKCS->DHPrivateKey; 171*46439007SCharles.Forsyth } 172*46439007SCharles.Forsyth }; 173*46439007SCharles.Forsyth 174*46439007SCharles.Forsyth ## Certificate Revocation List 175*46439007SCharles.Forsyth 176*46439007SCharles.Forsyth CRL: adt { 177*46439007SCharles.Forsyth version : int; # OPTIONAL; v2 178*46439007SCharles.Forsyth sig : ref AlgIdentifier; 179*46439007SCharles.Forsyth issuer : ref Name; 180*46439007SCharles.Forsyth this_update : int; 181*46439007SCharles.Forsyth next_update : int; # OPTIONAL 182*46439007SCharles.Forsyth revoked_certs : list of ref RevokedCert; # OPTIONAL 183*46439007SCharles.Forsyth exts : list of ref Extension; # OPTIONAL 184*46439007SCharles.Forsyth 185*46439007SCharles.Forsyth decode: fn(a: array of byte): (string, ref CRL); 186*46439007SCharles.Forsyth encode: fn(c: self ref CRL): (string, array of byte); 187*46439007SCharles.Forsyth tostring: fn(c: self ref CRL): string; 188*46439007SCharles.Forsyth is_revoked: fn(c: self ref CRL, sn: ref Keyring->IPint): int; 189*46439007SCharles.Forsyth }; 190*46439007SCharles.Forsyth 191*46439007SCharles.Forsyth RevokedCert: adt { 192*46439007SCharles.Forsyth user_cert : ref Keyring->IPint; # serial_number 193*46439007SCharles.Forsyth revoc_date : int; # OPTIONAL 194*46439007SCharles.Forsyth exts : list of ref Extension; # OPTIONAL; CRL entry extensions 195*46439007SCharles.Forsyth 196*46439007SCharles.Forsyth tostring: fn(rc: self ref RevokedCert): string; 197*46439007SCharles.Forsyth }; 198*46439007SCharles.Forsyth 199*46439007SCharles.Forsyth ## Certificate Extensions 200*46439007SCharles.Forsyth 201*46439007SCharles.Forsyth # get critical extensions 202*46439007SCharles.Forsyth cr_exts: fn(es: list of ref Extension): list of ref Extension; 203*46439007SCharles.Forsyth 204*46439007SCharles.Forsyth # get non-critical extensions 205*46439007SCharles.Forsyth noncr_exts: fn(es: list of ref Extension): list of ref Extension; 206*46439007SCharles.Forsyth 207*46439007SCharles.Forsyth # decode a list of extensions 208*46439007SCharles.Forsyth parse_exts: fn(es: list of ref Extension): (string, list of ref ExtClass); 209*46439007SCharles.Forsyth 210*46439007SCharles.Forsyth # extension classes 211*46439007SCharles.Forsyth ExtClass: adt { 212*46439007SCharles.Forsyth pick { 213*46439007SCharles.Forsyth AuthorityKeyIdentifier => 214*46439007SCharles.Forsyth id : array of byte; # OCTET STRING 215*46439007SCharles.Forsyth issuer : ref GeneralName; 216*46439007SCharles.Forsyth serial_number : ref Keyring->IPint; 217*46439007SCharles.Forsyth SubjectKeyIdentifier => 218*46439007SCharles.Forsyth id : array of byte; # OCTET STRING 219*46439007SCharles.Forsyth BasicConstraints => 220*46439007SCharles.Forsyth depth : int; # certificate path constraints 221*46439007SCharles.Forsyth KeyUsage => 222*46439007SCharles.Forsyth usage : int; 223*46439007SCharles.Forsyth PrivateKeyUsage => 224*46439007SCharles.Forsyth period : ref Validity; 225*46439007SCharles.Forsyth PolicyMapping => # (issuer, subject) domain policy pairs 226*46439007SCharles.Forsyth pairs : list of (ref ASN1->Oid, ref ASN1->Oid); 227*46439007SCharles.Forsyth CertificatePolicies => 228*46439007SCharles.Forsyth policies : list of ref PolicyInfo; 229*46439007SCharles.Forsyth IssuerAltName => 230*46439007SCharles.Forsyth alias : list of ref GeneralName; 231*46439007SCharles.Forsyth SubjectAltName => 232*46439007SCharles.Forsyth alias : list of ref GeneralName; 233*46439007SCharles.Forsyth NameConstraints => 234*46439007SCharles.Forsyth permitted : list of ref GSubtree; 235*46439007SCharles.Forsyth excluded : list of ref GSubtree; 236*46439007SCharles.Forsyth PolicyConstraints => 237*46439007SCharles.Forsyth require : int; 238*46439007SCharles.Forsyth inhibit : int; 239*46439007SCharles.Forsyth CRLNumber => 240*46439007SCharles.Forsyth curr : int; 241*46439007SCharles.Forsyth ReasonCode => 242*46439007SCharles.Forsyth code : int; 243*46439007SCharles.Forsyth InstructionCode => 244*46439007SCharles.Forsyth oid : ref ASN1->Oid; # hold instruction code field 245*46439007SCharles.Forsyth InvalidityDate => 246*46439007SCharles.Forsyth date : int; 247*46439007SCharles.Forsyth CRLDistributionPoint => 248*46439007SCharles.Forsyth ps : list of ref DistrPoint; 249*46439007SCharles.Forsyth IssuingDistributionPoint => 250*46439007SCharles.Forsyth name : ref DistrPointName; 251*46439007SCharles.Forsyth only_usercerts : int; # DEFAULT FALSE 252*46439007SCharles.Forsyth only_cacerts : int; # DEFAULT FALSE 253*46439007SCharles.Forsyth only_reasons : int; 254*46439007SCharles.Forsyth indirect_crl : int; # DEFAULT FALSE 255*46439007SCharles.Forsyth CertificateIssuer => 256*46439007SCharles.Forsyth names : list of ref GeneralName; 257*46439007SCharles.Forsyth DeltaCRLIndicator => 258*46439007SCharles.Forsyth number : ref Keyring->IPint; 259*46439007SCharles.Forsyth SubjectDirectoryAttributes => 260*46439007SCharles.Forsyth attrs : list of ref Attribute; 261*46439007SCharles.Forsyth UnknownType => 262*46439007SCharles.Forsyth ext : ref Extension; 263*46439007SCharles.Forsyth } 264*46439007SCharles.Forsyth 265*46439007SCharles.Forsyth decode: fn(ext: ref Extension): (string, ref ExtClass); 266*46439007SCharles.Forsyth encode: fn(et: self ref ExtClass, critical: int): ref Extension; 267*46439007SCharles.Forsyth tostring: fn(et: self ref ExtClass): string; 268*46439007SCharles.Forsyth }; 269*46439007SCharles.Forsyth 270*46439007SCharles.Forsyth # key usage 271*46439007SCharles.Forsyth KeyUsage_DigitalSignature, KeyUsage_NonRepudiation, KeyUsage_KeyEncipherment, 272*46439007SCharles.Forsyth KeyUsage_DataEncipherment, KeyUsage_KeyAgreement, KeyUsage_KeyCertSign, 273*46439007SCharles.Forsyth KeyUsage_CRLSign, KeyUsage_EncipherOnly, KeyUsage_DecipherOnly : con iota << 1; 274*46439007SCharles.Forsyth 275*46439007SCharles.Forsyth # CRL reason 276*46439007SCharles.Forsyth Reason_Unspecified, Reason_KeyCompromise, Reason_CACompromise, 277*46439007SCharles.Forsyth Reason_AffiliationChanged, Reason_Superseded, Reason_CessationOfOperation, 278*46439007SCharles.Forsyth Reason_CertificateHold, Reason_RemoveFromCRL : con iota << 1; 279*46439007SCharles.Forsyth 280*46439007SCharles.Forsyth # General Name 281*46439007SCharles.Forsyth GeneralName: adt { 282*46439007SCharles.Forsyth pick { 283*46439007SCharles.Forsyth otherName or # [0] 284*46439007SCharles.Forsyth rfc822Name or # [1] 285*46439007SCharles.Forsyth dNSName or # [2] 286*46439007SCharles.Forsyth x400Address or # [3] 287*46439007SCharles.Forsyth uniformResourceIdentifier => # [6] 288*46439007SCharles.Forsyth str : string; 289*46439007SCharles.Forsyth iPAddress => # [7] 290*46439007SCharles.Forsyth ip : array of byte; 291*46439007SCharles.Forsyth registeredID => # [8] 292*46439007SCharles.Forsyth oid : ref ASN1->Oid; 293*46439007SCharles.Forsyth ediPartyName => # [5] 294*46439007SCharles.Forsyth nameAssigner : ref Name; # [0] 295*46439007SCharles.Forsyth partyName : ref Name; # [1] 296*46439007SCharles.Forsyth directoryName => # [4] 297*46439007SCharles.Forsyth dir : ref Name; 298*46439007SCharles.Forsyth } 299*46439007SCharles.Forsyth 300*46439007SCharles.Forsyth tostring: fn(g: self ref GeneralName): string; 301*46439007SCharles.Forsyth }; 302*46439007SCharles.Forsyth 303*46439007SCharles.Forsyth # security policies 304*46439007SCharles.Forsyth PolicyInfo: adt { 305*46439007SCharles.Forsyth oid : ref ASN1->Oid; 306*46439007SCharles.Forsyth qualifiers : list of ref PolicyQualifier; 307*46439007SCharles.Forsyth 308*46439007SCharles.Forsyth tostring: fn(pi: self ref PolicyInfo): string; 309*46439007SCharles.Forsyth }; 310*46439007SCharles.Forsyth 311*46439007SCharles.Forsyth PolicyQualifier: adt { 312*46439007SCharles.Forsyth oid : ref ASN1->Oid; 313*46439007SCharles.Forsyth value : array of byte; # OCTET STRING; OPTIONAL 314*46439007SCharles.Forsyth 315*46439007SCharles.Forsyth tostring: fn(pq: self ref PolicyQualifier): string; 316*46439007SCharles.Forsyth }; 317*46439007SCharles.Forsyth 318*46439007SCharles.Forsyth GSubtree: adt { 319*46439007SCharles.Forsyth base : ref GeneralName; 320*46439007SCharles.Forsyth min : int; 321*46439007SCharles.Forsyth max : int; 322*46439007SCharles.Forsyth 323*46439007SCharles.Forsyth tostring: fn(gs: self ref GSubtree): string; 324*46439007SCharles.Forsyth }; 325*46439007SCharles.Forsyth 326*46439007SCharles.Forsyth # crl distribution point 327*46439007SCharles.Forsyth # with known reason code 328*46439007SCharles.Forsyth # Unused [0], KeyCompromise [1], CACompromise [2], AffilationChanged [3], 329*46439007SCharles.Forsyth # Superseded [4], CessationOfOperation [5], CertificateHold [6] 330*46439007SCharles.Forsyth DistrPoint: adt{ 331*46439007SCharles.Forsyth name : ref DistrPointName; 332*46439007SCharles.Forsyth reasons : int; 333*46439007SCharles.Forsyth issuer : list of ref GeneralName; 334*46439007SCharles.Forsyth 335*46439007SCharles.Forsyth tostring: fn(dp: self ref DistrPoint): string; 336*46439007SCharles.Forsyth }; 337*46439007SCharles.Forsyth 338*46439007SCharles.Forsyth DistrPointName: adt { 339*46439007SCharles.Forsyth full_name : list of ref GeneralName; 340*46439007SCharles.Forsyth rdname : list of ref RDName; 341*46439007SCharles.Forsyth }; 342*46439007SCharles.Forsyth 343*46439007SCharles.Forsyth Attribute: adt { 344*46439007SCharles.Forsyth id : ASN1->Oid; 345*46439007SCharles.Forsyth value : array of byte; 346*46439007SCharles.Forsyth }; 347*46439007SCharles.Forsyth}; 348*46439007SCharles.Forsyth 349*46439007SCharles.Forsyth#X509Attribute: module { 350*46439007SCharles.Forsyth# 351*46439007SCharles.Forsyth# ## Attribute Certificate 352*46439007SCharles.Forsyth# 353*46439007SCharles.Forsyth# AttrCert: adt { 354*46439007SCharles.Forsyth# version : int; # default v1 355*46439007SCharles.Forsyth# base_certid : ref IssuerSerial; # [0] 356*46439007SCharles.Forsyth# subject_name : list of ref GeneralName; # [1] 357*46439007SCharles.Forsyth# issuer : list of ref GeneralName; 358*46439007SCharles.Forsyth# serial_number : ref IPint; 359*46439007SCharles.Forsyth# validity : ref Validity; 360*46439007SCharles.Forsyth# attrs : list of ref Attribute; 361*46439007SCharles.Forsyth# issuer_uid : array of byte; # OPTIONAL 362*46439007SCharles.Forsyth# exts : list of ref Extension; # OPTIONAL 363*46439007SCharles.Forsyth# }; 364*46439007SCharles.Forsyth# 365*46439007SCharles.Forsyth# IssuerSerial: adt { 366*46439007SCharles.Forsyth# issuer : list of ref GeneralName; 367*46439007SCharles.Forsyth# serial : ref IPint; 368*46439007SCharles.Forsyth# issuer_uid : array of byte; # OPTIONAL 369*46439007SCharles.Forsyth# }; 370*46439007SCharles.Forsyth#}; 371