1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243
|
/** @file
* IPRT - Crypto - X.509, Public Key and Privilege Management Infrastructure.
*/
/*
* Copyright (C) 2014-2025 Oracle and/or its affiliates.
*
* This file is part of VirtualBox base platform packages, as
* available from https://www.virtualbox.org.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, in version 3 of the
* License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <https://www.gnu.org/licenses>.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
* in the VirtualBox distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
*/
#ifndef IPRT_INCLUDED_crypto_x509_h
#define IPRT_INCLUDED_crypto_x509_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif
#include <iprt/asn1.h>
#include <iprt/crypto/pem.h>
RT_C_DECLS_BEGIN
struct RTCRPKCS7SETOFCERTS;
/** @defgroup grp_rt_crypto Crypto
* @ingroup grp_rt
* @{
*/
/** @defgroup grp_rt_crx509 RTCrX509 - Public Key and Privilege Management Infrastructure.
* @{
*/
/**
* X.509 algorithm identifier (IPRT representation).
*/
typedef struct RTCRX509ALGORITHMIDENTIFIER
{
/** The sequence making up this algorithm identifier. */
RTASN1SEQUENCECORE SeqCore;
/** The algorithm object ID. */
RTASN1OBJID Algorithm;
/** Optional parameters specified by the algorithm. */
RTASN1DYNTYPE Parameters;
} RTCRX509ALGORITHMIDENTIFIER;
/** Poitner to the IPRT representation of a X.509 algorithm identifier. */
typedef RTCRX509ALGORITHMIDENTIFIER *PRTCRX509ALGORITHMIDENTIFIER;
/** Poitner to the const IPRT representation of a X.509 algorithm identifier. */
typedef RTCRX509ALGORITHMIDENTIFIER const *PCRTCRX509ALGORITHMIDENTIFIER;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509ALGORITHMIDENTIFIER, RTDECL, RTCrX509AlgorithmIdentifier, SeqCore.Asn1Core);
RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRX509ALGORITHMIDENTIFIERS, RTCRX509ALGORITHMIDENTIFIER, RTDECL, RTCrX509AlgorithmIdentifiers);
/**
* Tries to convert an X.509 digest algorithm ID into a RTDIGESTTYPE value.
*
* @returns Valid RTDIGESTTYPE on success, RTDIGESTTYPE_INVALID on failure.
* @param pThis The IPRT representation of a X.509 algorithm
* identifier object.
* @param fPureDigestsOnly Whether to only match IDs that only identify
* digest algorithms, or whether to also include
* IDs that mixes hash and encryption/whatever.
*/
RTDECL(RTDIGESTTYPE) RTCrX509AlgorithmIdentifier_GetDigestType(PCRTCRX509ALGORITHMIDENTIFIER pThis, bool fPureDigestsOnly);
/**
* Tries to figure the digest size of an X.509 digest algorithm ID.
*
* @returns The digest size in bytes, UINT32_MAX if unknown digest.
* @param pThis The IPRT representation of a X.509 algorithm
* identifier object.
* @param fPureDigestsOnly Whether to only match IDs that only identify
* digest algorithms, or whether to also include
* IDs that mixes hash and encryption/whatever.
*/
RTDECL(uint32_t) RTCrX509AlgorithmIdentifier_GetDigestSize(PCRTCRX509ALGORITHMIDENTIFIER pThis, bool fPureDigestsOnly);
/**
* Tries to get the encryption OID from the algorithm.
*
* @returns The encryption (cipher) OID on success, NULL on failure.
* @param pThis The IPRT representation of a X.509 algorithm
* identifier object.
* @param fMustIncludeHash Whether the algorithm ID represented by @a pThis
* must include a hash (true) or whether it is
* okay to accept pure encryption IDs as well
* (false).
*/
RTDECL(const char *) RTCrX509AlgorithmIdentifier_GetEncryptionOid(PCRTCRX509ALGORITHMIDENTIFIER pThis, bool fMustIncludeHash);
/**
* Tries to get the encryption OID from the given algorithm OID string.
*
* @returns The encryption (cipher) OID on success, NULL on failure.
* @param pszAlgorithmOid The IPRT representation of a X.509 algorithm
* identifier object.
* @param fMustIncludeHash Whether @a pszAlgorithmOid must include a hash
* (true) or whether it is okay to accept pure
* encryption IDs as well (false).
*/
RTDECL(const char *) RTCrX509AlgorithmIdentifier_GetEncryptionOidFromOid(const char *pszAlgorithmOid, bool fMustIncludeHash);
RTDECL(int) RTCrX509AlgorithmIdentifier_CompareWithString(PCRTCRX509ALGORITHMIDENTIFIER pThis, const char *pszObjId);
/**
* Compares a digest with an encrypted digest algorithm, checking if they
* specify the same digest.
*
* @returns 0 if same digest, -1 if the digest is unknown, 1 if the encrypted
* digest does not match.
* @param pDigest The digest algorithm.
* @param pEncryptedDigest The encrypted digest algorithm.
*/
RTDECL(int) RTCrX509AlgorithmIdentifier_CompareDigestAndEncryptedDigest(PCRTCRX509ALGORITHMIDENTIFIER pDigest,
PCRTCRX509ALGORITHMIDENTIFIER pEncryptedDigest);
/**
* Compares a digest OID with an encrypted digest algorithm OID, checking if
* they specify the same digest.
*
* @returns 0 if same digest, -1 if the digest is unknown, 1 if the encrypted
* digest does not match.
* @param pszDigestOid The digest algorithm OID.
* @param pszEncryptedDigestOid The encrypted digest algorithm OID.
*/
RTDECL(int) RTCrX509AlgorithmIdentifier_CompareDigestOidAndEncryptedDigestOid(const char *pszDigestOid,
const char *pszEncryptedDigestOid);
/**
* Combine the encryption algorithm with the digest algorithm.
*
* @returns OID of encrypted digest algorithm.
* @param pEncryption The encryption algorithm. Will work if this is
* the OID of an encrypted digest algorithm too, as
* long as it matches @a pDigest.
* @param pDigest The digest algorithm. Will work if this is the
* OID of an encrypted digest algorithm too, as
* long as it matches @a pEncryption.
*/
RTDECL(const char *) RTCrX509AlgorithmIdentifier_CombineEncryptionAndDigest(PCRTCRX509ALGORITHMIDENTIFIER pEncryption,
PCRTCRX509ALGORITHMIDENTIFIER pDigest);
/**
* Combine the encryption algorithm OID with the digest algorithm OID.
*
* @returns OID of encrypted digest algorithm.
* @param pszEncryptionOid The encryption algorithm. Will work if this is
* the OID of an encrypted digest algorithm too, as
* long as it matches @a pszDigestOid.
* @param pszDigestOid The digest algorithm. Will work if this is the
* OID of an encrypted digest algorithm too, as
* long as it matches @a pszEncryptionOid.
*/
RTDECL(const char *) RTCrX509AlgorithmIdentifier_CombineEncryptionOidAndDigestOid(const char *pszEncryptionOid,
const char *pszDigestOid);
/** @name Typical Digest Algorithm OIDs.
* @{ */
#define RTCRX509ALGORITHMIDENTIFIERID_MD2 "1.2.840.113549.2.2"
#define RTCRX509ALGORITHMIDENTIFIERID_MD4 "1.2.840.113549.2.4"
#define RTCRX509ALGORITHMIDENTIFIERID_MD5 "1.2.840.113549.2.5"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA0 "1.3.14.3.2.18"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA1 "1.3.14.3.2.26"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA256 "2.16.840.1.101.3.4.2.1"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA384 "2.16.840.1.101.3.4.2.2"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA512 "2.16.840.1.101.3.4.2.3"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA224 "2.16.840.1.101.3.4.2.4"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA512T224 "2.16.840.1.101.3.4.2.5"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA512T256 "2.16.840.1.101.3.4.2.6"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA3_224 "2.16.840.1.101.3.4.2.7"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA3_256 "2.16.840.1.101.3.4.2.8"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA3_384 "2.16.840.1.101.3.4.2.9"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA3_512 "2.16.840.1.101.3.4.2.10"
#define RTCRX509ALGORITHMIDENTIFIERID_WHIRLPOOL "1.0.10118.3.0.55"
/** @} */
/** @name Encrypted Digest Algorithm OIDs.
* @remarks The PKCS variants are the default ones, alternative OID are marked
* as such.
* @{ */
#define RTCRX509ALGORITHMIDENTIFIERID_RSA "1.2.840.113549.1.1.1"
#define RTCRX509ALGORITHMIDENTIFIERID_MD2_WITH_RSA "1.2.840.113549.1.1.2"
#define RTCRX509ALGORITHMIDENTIFIERID_MD4_WITH_RSA "1.2.840.113549.1.1.3"
#define RTCRX509ALGORITHMIDENTIFIERID_MD5_WITH_RSA "1.2.840.113549.1.1.4"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA1_WITH_RSA "1.2.840.113549.1.1.5"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA256_WITH_RSA "1.2.840.113549.1.1.11"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA384_WITH_RSA "1.2.840.113549.1.1.12"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA512_WITH_RSA "1.2.840.113549.1.1.13"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA224_WITH_RSA "1.2.840.113549.1.1.14"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA512T224_WITH_RSA "1.2.840.113549.1.1.15"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA512T256_WITH_RSA "1.2.840.113549.1.1.16"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA3_224_WITH_RSA "2.16.840.1.101.3.4.3.13"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA3_256_WITH_RSA "2.16.840.1.101.3.4.3.14"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA3_384_WITH_RSA "2.16.840.1.101.3.4.3.15"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA3_512_WITH_RSA "2.16.840.1.101.3.4.3.16"
#define RTCRX509ALGORITHMIDENTIFIERID_ECDSA "1.2.840.10045.2.1"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA1_WITH_ECDSA "1.2.840.10045.4.1"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA224_WITH_ECDSA "1.2.840.10045.4.3.1"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA256_WITH_ECDSA "1.2.840.10045.4.3.2"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA384_WITH_ECDSA "1.2.840.10045.4.3.3"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA512_WITH_ECDSA "1.2.840.10045.4.3.4"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA3_224_WITH_ECDSA "2.16.840.1.101.3.4.3.9"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA3_256_WITH_ECDSA "2.16.840.1.101.3.4.3.10"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA3_384_WITH_ECDSA "2.16.840.1.101.3.4.3.11"
#define RTCRX509ALGORITHMIDENTIFIERID_SHA3_512_WITH_ECDSA "2.16.840.1.101.3.4.3.12"
/** @} */
/**
* One X.509 AttributeTypeAndValue (IPRT representation).
*/
typedef struct RTCRX509ATTRIBUTETYPEANDVALUE
{
/** Sequence core. */
RTASN1SEQUENCECORE SeqCore;
/** The attribute type (object ID). */
RTASN1OBJID Type;
/** The attribute value (what it is is defined by Type). */
RTASN1DYNTYPE Value;
} RTCRX509ATTRIBUTETYPEANDVALUE;
/** Pointer to a X.509 AttributeTypeAndValue (IPRT representation). */
typedef RTCRX509ATTRIBUTETYPEANDVALUE *PRTCRX509ATTRIBUTETYPEANDVALUE;
/** Pointer to a const X.509 AttributeTypeAndValue (IPRT representation). */
typedef RTCRX509ATTRIBUTETYPEANDVALUE const *PCRTCRX509ATTRIBUTETYPEANDVALUE;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509ATTRIBUTETYPEANDVALUE, RTDECL, RTCrX509AttributeTypeAndValue, SeqCore.Asn1Core);
RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRX509ATTRIBUTETYPEANDVALUES, RTCRX509ATTRIBUTETYPEANDVALUE, RTDECL, RTCrX509AttributeTypeAndValues);
RTASN1TYPE_ALIAS(RTCRX509RELATIVEDISTINGUISHEDNAME, RTCRX509ATTRIBUTETYPEANDVALUES, RTCrX509RelativeDistinguishedName, RTCrX509AttributeTypeAndValues);
RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTCRX509NAME, RTCRX509RELATIVEDISTINGUISHEDNAME, RTDECL, RTCrX509Name);
RTDECL(int) RTCrX509Name_CheckSanity(PCRTCRX509NAME pName, uint32_t fFlags, PRTERRINFO pErrInfo, const char *pszErrorTag);
RTDECL(bool) RTCrX509Name_MatchByRfc5280(PCRTCRX509NAME pLeft, PCRTCRX509NAME pRight);
/**
* Name constraint matching (RFC-5280).
*
* @returns true on match, false on mismatch.
* @param pConstraint The constraint name.
* @param pName The name to match against the constraint.
* @sa RTCrX509GeneralName_ConstraintMatch,
* RTCrX509RelativeDistinguishedName_ConstraintMatch
*/
RTDECL(bool) RTCrX509Name_ConstraintMatch(PCRTCRX509NAME pConstraint, PCRTCRX509NAME pName);
RTDECL(int) RTCrX509Name_RecodeAsUtf8(PRTCRX509NAME pThis, PCRTASN1ALLOCATORVTABLE pAllocator);
/**
* Matches the directory name against a comma separated list of the component
* strings (case sensitive).
*
* @returns true if match, false if mismatch.
* @param pThis The name object.
* @param pszString The string to match against. For example:
* "C=US, ST=California, L=Redwood Shores, O=Oracle Corporation"
*
* @remarks This is doing a straight compare, no extra effort is expended in
* dealing with different component order. If the component order
* differs, there won't be any match.
*/
RTDECL(bool) RTCrX509Name_MatchWithString(PCRTCRX509NAME pThis, const char *pszString);
/**
* Formats the name as a command separated list of components with type
* prefixes.
*
* The output of this function is suitable for use with
* RTCrX509Name_MatchWithString.
*
* @returns IPRT status code.
* @param pThis The name object.
* @param pszBuf The output buffer.
* @param cbBuf The size of the output buffer.
* @param pcbActual Where to return the number of bytes required for the
* output, including the null terminator character.
* Optional.
*/
RTDECL(int) RTCrX509Name_FormatAsString(PCRTCRX509NAME pThis, char *pszBuf, size_t cbBuf, size_t *pcbActual);
/**
* Looks up the RDN ID and returns the short name for it, if found.
*
* @returns Short name (e.g. 'CN') or NULL.
* @param pRdnId The RDN ID to look up.
*/
RTDECL(const char *) RTCrX509Name_GetShortRdn(PCRTASN1OBJID pRdnId);
/**
* One X.509 OtherName (IPRT representation).
*/
typedef struct RTCRX509OTHERNAME
{
/** The sequence core. */
RTASN1SEQUENCECORE SeqCore;
/** The name type identifier. */
RTASN1OBJID TypeId;
/** The name value (explicit tag 0). */
RTASN1DYNTYPE Value;
} RTCRX509OTHERNAME;
/** Pointer to a X.509 OtherName (IPRT representation). */
typedef RTCRX509OTHERNAME *PRTCRX509OTHERNAME;
/** Pointer to a const X.509 OtherName (IPRT representation). */
typedef RTCRX509OTHERNAME const *PCRTCRX509OTHERNAME;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509OTHERNAME, RTDECL, RTCrX509OtherName, SeqCore.Asn1Core);
typedef enum RTCRX509GENERALNAMECHOICE
{
RTCRX509GENERALNAMECHOICE_INVALID = 0,
RTCRX509GENERALNAMECHOICE_OTHER_NAME,
RTCRX509GENERALNAMECHOICE_RFC822_NAME,
RTCRX509GENERALNAMECHOICE_DNS_NAME,
RTCRX509GENERALNAMECHOICE_X400_ADDRESS,
RTCRX509GENERALNAMECHOICE_DIRECTORY_NAME,
RTCRX509GENERALNAMECHOICE_EDI_PARTY_NAME,
RTCRX509GENERALNAMECHOICE_URI,
RTCRX509GENERALNAMECHOICE_IP_ADDRESS,
RTCRX509GENERALNAMECHOICE_REGISTERED_ID,
RTCRX509GENERALNAMECHOICE_END,
RTCRX509GENERALNAMECHOICE_32BIT_HACK = 0x7fffffff
} RTCRX509GENERALNAMECHOICE;
/**
* One X.509 GeneralName (IPRT representation).
*
* This is represented as a union. Use the RTCRX509GENERALNAME_IS_XXX predicate
* macros to figure out which member is valid (Asn1Core is always valid).
*/
typedef struct RTCRX509GENERALNAME
{
/** Dummy ASN.1 record, not encoded. */
RTASN1DUMMY Dummy;
/** The value allocation. */
RTASN1ALLOCATION Allocation;
/** The choice of value. */
RTCRX509GENERALNAMECHOICE enmChoice;
/** The value union. */
union
{
/** Tag 0: Other Name. */
PRTCRX509OTHERNAME pT0_OtherName;
/** Tag 1: RFC-822 Name. */
PRTASN1STRING pT1_Rfc822;
/** Tag 2: DNS name. */
PRTASN1STRING pT2_DnsName;
/** Tag 3: X.400 Address. */
struct
{
/** Context tag 3. */
RTASN1CONTEXTTAG3 CtxTag3;
/** Later. */
RTASN1DYNTYPE X400Address;
} *pT3;
/** Tag 4: Directory Name. */
struct
{
/** Context tag 4. */
RTASN1CONTEXTTAG4 CtxTag4;
/** Directory name. */
RTCRX509NAME DirectoryName;
} *pT4;
/** Tag 5: EDI Party Name. */
struct
{
/** Context tag 5. */
RTASN1CONTEXTTAG5 CtxTag5;
/** Later. */
RTASN1DYNTYPE EdiPartyName;
} *pT5;
/** Tag 6: URI. */
PRTASN1STRING pT6_Uri;
/** Tag 7: IP address. Either 4/8 (IPv4) or 16/32 (IPv16) octets long. */
PRTASN1OCTETSTRING pT7_IpAddress;
/** Tag 8: Registered ID. */
PRTASN1OBJID pT8_RegisteredId;
} u;
} RTCRX509GENERALNAME;
/** Pointer to the IPRT representation of an X.509 general name. */
typedef RTCRX509GENERALNAME *PRTCRX509GENERALNAME;
/** Pointer to the const IPRT representation of an X.509 general name. */
typedef RTCRX509GENERALNAME const *PCRTCRX509GENERALNAME;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509GENERALNAME, RTDECL, RTCrX509GeneralName, Dummy.Asn1Core);
/** @name RTCRX509GENERALNAME tag predicates.
* @{ */
#define RTCRX509GENERALNAME_IS_OTHER_NAME(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_OTHER_NAME)
#define RTCRX509GENERALNAME_IS_RFC822_NAME(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_RFC822_NAME)
#define RTCRX509GENERALNAME_IS_DNS_NAME(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_DNS_NAME)
#define RTCRX509GENERALNAME_IS_X400_ADDRESS(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_X400_ADDRESS)
#define RTCRX509GENERALNAME_IS_DIRECTORY_NAME(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_DIRECTORY_NAME)
#define RTCRX509GENERALNAME_IS_EDI_PARTY_NAME(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_EDI_PARTY_NAME)
#define RTCRX509GENERALNAME_IS_URI(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_URI)
#define RTCRX509GENERALNAME_IS_IP_ADDRESS(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_IP_ADDRESS)
#define RTCRX509GENERALNAME_IS_REGISTERED_ID(a_GenName) ((a_GenName)->enmChoice == RTCRX509GENERALNAMECHOICE_REGISTERED_ID)
/** @} */
RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTCRX509GENERALNAMES, RTCRX509GENERALNAME, RTDECL, RTCrX509GeneralNames);
RTDECL(bool) RTCrX509GeneralName_ConstraintMatch(PCRTCRX509GENERALNAME pConstraint, PCRTCRX509GENERALNAME pName);
/**
* X.509 Validity (IPRT representation).
*/
typedef struct RTCRX509VALIDITY
{
/** Core sequence bits. */
RTASN1SEQUENCECORE SeqCore;
/** Effective starting. */
RTASN1TIME NotBefore;
/** Expires after. */
RTASN1TIME NotAfter;
} RTCRX509VALIDITY;
/** Pointer to the IPRT representation of an X.509 validity sequence. */
typedef RTCRX509VALIDITY *PRTCRX509VALIDITY;
/** Pointer ot the const IPRT representation of an X.509 validity sequence. */
typedef RTCRX509VALIDITY const *PCRTCRX509VALIDITY;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509VALIDITY, RTDECL, RTCrX509Validity, SeqCore.Asn1Core);
RTDECL(bool) RTCrX509Validity_IsValidAtTimeSpec(PCRTCRX509VALIDITY pThis, PCRTTIMESPEC pTimeSpec);
#if 0
/**
* X.509 UniqueIdentifier (IPRT representation).
*/
typedef struct RTCRX509UNIQUEIDENTIFIER
{
/** Representation is a bit string. */
RTASN1BITSTRING BitString;
} RTCRX509UNIQUEIDENTIFIER;
/** Pointer to the IPRT representation of an X.509 unique identifier. */
typedef RTCRX509UNIQUEIDENTIFIER *PRTCRX509UNIQUEIDENTIFIER;
/** Pointer to the const IPRT representation of an X.509 unique identifier. */
typedef RTCRX509UNIQUEIDENTIFIER const *PCRTCRX509UNIQUEIDENTIFIER;
RTASN1TYPE_STANDARD_PROTOTYPES_NO_GET_CORE(RTCRX509UNIQUEIDENTIFIER, RTDECL, RTCrX509UniqueIdentifier);
#endif
RTASN1TYPE_ALIAS(RTCRX509UNIQUEIDENTIFIER, RTASN1BITSTRING, RTCrX509UniqueIdentifier, RTAsn1BitString);
/**
* X.509 SubjectPublicKeyInfo (IPRT representation).
*/
typedef struct RTCRX509SUBJECTPUBLICKEYINFO
{
/** Core sequence bits. */
RTASN1SEQUENCECORE SeqCore;
/** The algorithm used with the public key. */
RTCRX509ALGORITHMIDENTIFIER Algorithm;
/** A bit string containing the public key.
*
* For algorithms like rsaEncryption this is generally a sequence of two
* integers, where the first one has lots of bits, and the second one being a
* modulous value. These are details specific to the algorithm and not relevant
* when validating the certificate chain. */
RTASN1BITSTRING SubjectPublicKey;
} RTCRX509SUBJECTPUBLICKEYINFO;
/** Pointer to the IPRT representation of an X.509 subject public key info
* sequence. */
typedef RTCRX509SUBJECTPUBLICKEYINFO *PRTCRX509SUBJECTPUBLICKEYINFO;
/** Pointer to the const IPRT representation of an X.509 subject public key info
* sequence. */
typedef RTCRX509SUBJECTPUBLICKEYINFO const *PCRTCRX509SUBJECTPUBLICKEYINFO;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509SUBJECTPUBLICKEYINFO, RTDECL, RTCrX509SubjectPublicKeyInfo, SeqCore.Asn1Core);
/**
* One X.509 AuthorityKeyIdentifier (IPRT representation).
*/
typedef struct RTCRX509AUTHORITYKEYIDENTIFIER
{
/** Sequence core. */
RTASN1SEQUENCECORE SeqCore;
/** Tag 0, optional, implicit: Key identifier. */
RTASN1OCTETSTRING KeyIdentifier;
/** Tag 1, optional, implicit: Issuer name. */
RTCRX509GENERALNAMES AuthorityCertIssuer;
/** Tag 2, optional, implicit: Serial number of issuer. */
RTASN1INTEGER AuthorityCertSerialNumber;
} RTCRX509AUTHORITYKEYIDENTIFIER;
/** Pointer to the IPRT representation of an X.509 AuthorityKeyIdentifier
* sequence. */
typedef RTCRX509AUTHORITYKEYIDENTIFIER *PRTCRX509AUTHORITYKEYIDENTIFIER;
/** Pointer to the const IPRT representation of an X.509 AuthorityKeyIdentifier
* sequence. */
typedef RTCRX509AUTHORITYKEYIDENTIFIER const *PCRTCRX509AUTHORITYKEYIDENTIFIER;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509AUTHORITYKEYIDENTIFIER, RTDECL, RTCrX509AuthorityKeyIdentifier, SeqCore.Asn1Core);
/**
* One X.509 OldAuthorityKeyIdentifier (IPRT representation).
*/
typedef struct RTCRX509OLDAUTHORITYKEYIDENTIFIER
{
/** Sequence core. */
RTASN1SEQUENCECORE SeqCore;
/** Tag 0, optional, implicit: Key identifier. */
RTASN1OCTETSTRING KeyIdentifier;
struct
{
RTASN1CONTEXTTAG1 CtxTag1;
/** Tag 1, optional, implicit: Issuer name. */
RTCRX509NAME AuthorityCertIssuer;
} T1;
/** Tag 2, optional, implicit: Serial number of issuer. */
RTASN1INTEGER AuthorityCertSerialNumber;
} RTCRX509OLDAUTHORITYKEYIDENTIFIER;
/** Pointer to the IPRT representation of an X.509 AuthorityKeyIdentifier
* sequence. */
typedef RTCRX509OLDAUTHORITYKEYIDENTIFIER *PRTCRX509OLDAUTHORITYKEYIDENTIFIER;
/** Pointer to the const IPRT representation of an X.509 AuthorityKeyIdentifier
* sequence. */
typedef RTCRX509OLDAUTHORITYKEYIDENTIFIER const *PCRTCRX509OLDAUTHORITYKEYIDENTIFIER;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509OLDAUTHORITYKEYIDENTIFIER, RTDECL, RTCrX509OldAuthorityKeyIdentifier, SeqCore.Asn1Core);
/**
* One X.509 PolicyQualifierInfo (IPRT representation).
*/
typedef struct RTCRX509POLICYQUALIFIERINFO
{
/** Core sequence bits. */
RTASN1SEQUENCECORE SeqCore;
/** The policy object ID. */
RTASN1OBJID PolicyQualifierId;
/** Anything defined by the policy qualifier id. */
RTASN1DYNTYPE Qualifier;
} RTCRX509POLICYQUALIFIERINFO;
/** Pointer to the IPRT representation of an X.509 PolicyQualifierInfo
* sequence. */
typedef RTCRX509POLICYQUALIFIERINFO *PRTCRX509POLICYQUALIFIERINFO;
/** Pointer to the const IPRT representation of an X.509 PolicyQualifierInfo
* sequence. */
typedef RTCRX509POLICYQUALIFIERINFO const *PCRTCRX509POLICYQUALIFIERINFO;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509POLICYQUALIFIERINFO, RTDECL, RTCrX509PolicyQualifierInfo, SeqCore.Asn1Core);
RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTCRX509POLICYQUALIFIERINFOS, RTCRX509POLICYQUALIFIERINFO, RTDECL, RTCrX509PolicyQualifierInfos);
/**
* One X.509 PolicyInformation (IPRT representation).
*/
typedef struct RTCRX509POLICYINFORMATION
{
/** Core sequence bits. */
RTASN1SEQUENCECORE SeqCore;
/** The policy object ID. */
RTASN1OBJID PolicyIdentifier;
/** Optional sequence of policy qualifiers. */
RTCRX509POLICYQUALIFIERINFOS PolicyQualifiers;
} RTCRX509POLICYINFORMATION;
/** Pointer to the IPRT representation of an X.509 PolicyInformation
* sequence. */
typedef RTCRX509POLICYINFORMATION *PRTCRX509POLICYINFORMATION;
/** Pointer to the const IPRT representation of an X.509 PolicyInformation
* sequence. */
typedef RTCRX509POLICYINFORMATION const *PCRTCRX509POLICYINFORMATION;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509POLICYINFORMATION, RTDECL, RTCrX509PolicyInformation, SeqCore.Asn1Core);
RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTCRX509CERTIFICATEPOLICIES, RTCRX509POLICYINFORMATION, RTDECL, RTCrX509CertificatePolicies);
/** Sepcial policy object ID that matches any policy. */
#define RTCRX509_ID_CE_CP_ANY_POLICY_OID "2.5.29.32.0"
/**
* One X.509 PolicyMapping (IPRT representation).
*/
typedef struct RTCRX509POLICYMAPPING
{
/** Core sequence bits. */
RTASN1SEQUENCECORE SeqCore;
/** Issuer policy ID. */
RTASN1OBJID IssuerDomainPolicy;
/** Subject policy ID. */
RTASN1OBJID SubjectDomainPolicy;
} RTCRX509POLICYMAPPING;
/** Pointer to the IPRT representation of a sequence of X.509 PolicyMapping. */
typedef RTCRX509POLICYMAPPING *PRTCRX509POLICYMAPPING;
/** Pointer to the const IPRT representation of a sequence of X.509
* PolicyMapping. */
typedef RTCRX509POLICYMAPPING const *PCRTCRX509POLICYMAPPING;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509POLICYMAPPING, RTDECL, RTCrX509PolicyMapping, SeqCore.Asn1Core);
RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTCRX509POLICYMAPPINGS, RTCRX509POLICYMAPPING, RTDECL, RTCrX509PolicyMappings);
/**
* X.509 BasicConstraints (IPRT representation).
*/
typedef struct RTCRX509BASICCONSTRAINTS
{
/** Core sequence bits. */
RTASN1SEQUENCECORE SeqCore;
/** Is this ia certficiate authority? Default to false. */
RTASN1BOOLEAN CA;
/** Path length constraint. */
RTASN1INTEGER PathLenConstraint;
} RTCRX509BASICCONSTRAINTS;
/** Pointer to the IPRT representation of a sequence of X.509
* BasicConstraints. */
typedef RTCRX509BASICCONSTRAINTS *PRTCRX509BASICCONSTRAINTS;
/** Pointer to the const IPRT representation of a sequence of X.509
* BasicConstraints. */
typedef RTCRX509BASICCONSTRAINTS const *PCRTCRX509BASICCONSTRAINTS;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509BASICCONSTRAINTS, RTDECL, RTCrX509BasicConstraints, SeqCore.Asn1Core);
/**
* X.509 GeneralSubtree (IPRT representation).
*/
typedef struct RTCRX509GENERALSUBTREE
{
/** Core sequence bits. */
RTASN1SEQUENCECORE SeqCore;
/** Base name. */
RTCRX509GENERALNAME Base;
/** Tag 0, optional: Minimum, default 0. Fixed at 0 by RFC-5280. */
RTASN1INTEGER Minimum;
/** Tag 1, optional: Maximum. Fixed as not-present by RFC-5280. */
RTASN1INTEGER Maximum;
} RTCRX509GENERALSUBTREE;
/** Pointer to the IPRT representation of a sequence of X.509 GeneralSubtree. */
typedef RTCRX509GENERALSUBTREE *PRTCRX509GENERALSUBTREE;
/** Pointer to the const IPRT representation of a sequence of X.509
* GeneralSubtree. */
typedef RTCRX509GENERALSUBTREE const *PCRTCRX509GENERALSUBTREE;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509GENERALSUBTREE, RTDECL, RTCrX509GeneralSubtree, SeqCore.Asn1Core);
RTDECL(bool) RTCrX509GeneralSubtree_ConstraintMatch(PCRTCRX509GENERALSUBTREE pConstraint, PCRTCRX509GENERALSUBTREE pName);
RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTCRX509GENERALSUBTREES, RTCRX509GENERALSUBTREE, RTDECL, RTCrX509GeneralSubtrees);
/**
* X.509 NameConstraints (IPRT representation).
*/
typedef struct RTCRX509NAMECONSTRAINTS
{
/** Core sequence bits. */
RTASN1SEQUENCECORE SeqCore;
/** Tag 0, optional: Permitted subtrees. */
struct
{
/** Context tag. */
RTASN1CONTEXTTAG0 CtxTag0;
/** The permitted subtrees. */
RTCRX509GENERALSUBTREES PermittedSubtrees;
} T0;
/** Tag 1, optional: Excluded subtrees. */
struct
{
/** Context tag. */
RTASN1CONTEXTTAG1 CtxTag1;
/** The excluded subtrees. */
RTCRX509GENERALSUBTREES ExcludedSubtrees;
} T1;
} RTCRX509NAMECONSTRAINTS;
/** Pointer to the IPRT representation of a sequence of X.509
* NameConstraints. */
typedef RTCRX509NAMECONSTRAINTS *PRTCRX509NAMECONSTRAINTS;
/** Pointer to the const IPRT representation of a sequence of X.509
* NameConstraints. */
typedef RTCRX509NAMECONSTRAINTS const *PCRTCRX509NAMECONSTRAINTS;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509NAMECONSTRAINTS, RTDECL, RTCrX509NameConstraints, SeqCore.Asn1Core);
/**
* X.509 PolicyConstraints (IPRT representation).
*/
typedef struct RTCRX509POLICYCONSTRAINTS
{
/** Core sequence bits. */
RTASN1SEQUENCECORE SeqCore;
/** Tag 0, optional: Certificates before an explicit policy is required. */
RTASN1INTEGER RequireExplicitPolicy;
/** Tag 1, optional: Certificates before policy mapping is inhibited. */
RTASN1INTEGER InhibitPolicyMapping;
} RTCRX509POLICYCONSTRAINTS;
/** Pointer to the IPRT representation of a sequence of X.509
* PolicyConstraints. */
typedef RTCRX509POLICYCONSTRAINTS *PRTCRX509POLICYCONSTRAINTS;
/** Pointer to the const IPRT representation of a sequence of X.509
* PolicyConstraints. */
typedef RTCRX509POLICYCONSTRAINTS const *PCRTCRX509POLICYCONSTRAINTS;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509POLICYCONSTRAINTS, RTDECL, RTCrX509PolicyConstraints, SeqCore.Asn1Core);
/**
* Indicates what an X.509 extension value encapsulates.
*/
typedef enum RTCRX509EXTENSIONVALUE
{
RTCRX509EXTENSIONVALUE_INVALID = 0,
/** Unknown, no decoding available just the octet string. */
RTCRX509EXTENSIONVALUE_UNKNOWN,
/** Unencapsulated (i.e. octet string). */
RTCRX509EXTENSIONVALUE_NOT_ENCAPSULATED,
/** Bit string (RTASN1BITSTRING). */
RTCRX509EXTENSIONVALUE_BIT_STRING,
/** Octet string (RTASN1OCTETSTRING). */
RTCRX509EXTENSIONVALUE_OCTET_STRING,
/** Integer string (RTASN1INTEGER). */
RTCRX509EXTENSIONVALUE_INTEGER,
/** Sequence of object identifiers (RTASN1SEQOFOBJIDS). */
RTCRX509EXTENSIONVALUE_SEQ_OF_OBJ_IDS,
/** Authority key identifier (RTCRX509AUTHORITYKEYIDENTIFIER). */
RTCRX509EXTENSIONVALUE_AUTHORITY_KEY_IDENTIFIER,
/** Old Authority key identifier (RTCRX509OLDAUTHORITYKEYIDENTIFIER). */
RTCRX509EXTENSIONVALUE_OLD_AUTHORITY_KEY_IDENTIFIER,
/** Certificate policies (RTCRX509CERTIFICATEPOLICIES). */
RTCRX509EXTENSIONVALUE_CERTIFICATE_POLICIES,
/** Sequence of policy mappings (RTCRX509POLICYMAPPINGS). */
RTCRX509EXTENSIONVALUE_POLICY_MAPPINGS,
/** Basic constraints (RTCRX509BASICCONSTRAINTS). */
RTCRX509EXTENSIONVALUE_BASIC_CONSTRAINTS,
/** Name constraints (RTCRX509NAMECONSTRAINTS). */
RTCRX509EXTENSIONVALUE_NAME_CONSTRAINTS,
/** Policy constraints (RTCRX509POLICYCONSTRAINTS). */
RTCRX509EXTENSIONVALUE_POLICY_CONSTRAINTS,
/** Sequence of general names (RTCRX509GENERALNAMES). */
RTCRX509EXTENSIONVALUE_GENERAL_NAMES,
/** Blow the type up to 32-bits. */
RTCRX509EXTENSIONVALUE_32BIT_HACK = 0x7fffffff
} RTCRX509EXTENSIONVALUE;
/**
* One X.509 Extension (IPRT representation).
*/
typedef struct RTCRX509EXTENSION
{
/** Core sequence bits. */
RTASN1SEQUENCECORE SeqCore;
/** Extension ID. */
RTASN1OBJID ExtnId;
/** Whether this is critical (default @c false). */
RTASN1BOOLEAN Critical;
/** Indicates what ExtnValue.pEncapsulated points at. */
RTCRX509EXTENSIONVALUE enmValue;
/** The value.
* Contains extension specific data that we don't yet parse. */
RTASN1OCTETSTRING ExtnValue;
} RTCRX509EXTENSION;
/** Pointer to the IPRT representation of one X.509 extensions. */
typedef RTCRX509EXTENSION *PRTCRX509EXTENSION;
/** Pointer to the const IPRT representation of one X.509 extension. */
typedef RTCRX509EXTENSION const *PCRTCRX509EXTENSION;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509EXTENSION, RTDECL, RTCrX509Extension, SeqCore.Asn1Core);
RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTCRX509EXTENSIONS, RTCRX509EXTENSION, RTDECL, RTCrX509Extensions);
RTDECL(int) RTCrX509Extension_ExtnValue_DecodeAsn1(PRTASN1CURSOR pCursor, uint32_t fFlags,
PRTCRX509EXTENSION pThis, const char *pszErrorTag);
/**
* X.509 To-be-signed certificate information (IPRT representation).
*/
typedef struct RTCRX509TBSCERTIFICATE
{
/** Sequence core. */
RTASN1SEQUENCECORE SeqCore;
/** Structure version. */
struct
{
/** Context tag with value 0. */
RTASN1CONTEXTTAG0 CtxTag0;
/** The actual value (RTCRX509TBSCERTIFICATE_V1, ...). */
RTASN1INTEGER Version;
} T0;
/** The serial number of the certificate. */
RTASN1INTEGER SerialNumber;
/** The signature algorithm. */
RTCRX509ALGORITHMIDENTIFIER Signature;
/** The issuer name. */
RTCRX509NAME Issuer;
/** The certificate validity period. */
RTCRX509VALIDITY Validity;
/** The subject name. */
RTCRX509NAME Subject;
/** The public key for this certificate. */
RTCRX509SUBJECTPUBLICKEYINFO SubjectPublicKeyInfo;
/** Issuer unique identifier (optional, version >= v2). */
struct
{
/** Context tag with value 1. */
RTASN1CONTEXTTAG1 CtxTag1;
/** The unique identifier value. */
RTCRX509UNIQUEIDENTIFIER IssuerUniqueId;
} T1;
/** Subject unique identifier (optional, version >= v2). */
struct
{
/** Context tag with value 2. */
RTASN1CONTEXTTAG2 CtxTag2;
/** The unique identifier value. */
RTCRX509UNIQUEIDENTIFIER SubjectUniqueId;
} T2;
/** Extensions (optional, version >= v3). */
struct
{
/** Context tag with value 3. */
RTASN1CONTEXTTAG3 CtxTag3;
/** The unique identifier value. */
RTCRX509EXTENSIONS Extensions;
/** Extensions summary flags (RTCRX509TBSCERTIFICATE_F_PRESENT_XXX). */
uint32_t fFlags;
/** Key usage flags (RTCRX509CERT_KEY_USAGE_F_XXX). */
uint32_t fKeyUsage;
/** Extended key usage flags (RTCRX509CERT_EKU_F_XXX). */
uint64_t fExtKeyUsage;
/** Pointer to the authority key ID extension if present. */
PCRTCRX509AUTHORITYKEYIDENTIFIER pAuthorityKeyIdentifier;
/** Pointer to the OLD authority key ID extension if present. */
PCRTCRX509OLDAUTHORITYKEYIDENTIFIER pOldAuthorityKeyIdentifier;
/** Pointer to the subject key ID extension if present. */
PCRTASN1OCTETSTRING pSubjectKeyIdentifier;
/** Pointer to the alternative subject name extension if present. */
PCRTCRX509GENERALNAMES pAltSubjectName;
/** Pointer to the alternative issuer name extension if present. */
PCRTCRX509GENERALNAMES pAltIssuerName;
/** Pointer to the certificate policies extension if present. */
PCRTCRX509CERTIFICATEPOLICIES pCertificatePolicies;
/** Pointer to the policy mappings extension if present. */
PCRTCRX509POLICYMAPPINGS pPolicyMappings;
/** Pointer to the basic constraints extension if present. */
PCRTCRX509BASICCONSTRAINTS pBasicConstraints;
/** Pointer to the name constraints extension if present. */
PCRTCRX509NAMECONSTRAINTS pNameConstraints;
/** Pointer to the policy constraints extension if present. */
PCRTCRX509POLICYCONSTRAINTS pPolicyConstraints;
/** Pointer to the inhibit anyPolicy extension if present. */
PCRTASN1INTEGER pInhibitAnyPolicy;
} T3;
} RTCRX509TBSCERTIFICATE;
/** Pointer to the IPRT representation of a X.509 TBSCertificate. */
typedef RTCRX509TBSCERTIFICATE *PRTCRX509TBSCERTIFICATE;
/** Pointer to the const IPRT representation of a X.509 TBSCertificate. */
typedef RTCRX509TBSCERTIFICATE const *PCRTCRX509TBSCERTIFICATE;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509TBSCERTIFICATE, RTDECL, RTCrX509TbsCertificate, SeqCore.Asn1Core);
/** @name RTCRX509TBSCERTIFICATE::T0.Version values.
* @{ */
#define RTCRX509TBSCERTIFICATE_V1 0
#define RTCRX509TBSCERTIFICATE_V2 1
#define RTCRX509TBSCERTIFICATE_V3 2
/** @} */
/** @name RTCRX509TBSCERTIFICATE::T3.fFlags values.
* @{ */
#define RTCRX509TBSCERTIFICATE_F_PRESENT_KEY_USAGE RT_BIT_32(0)
#define RTCRX509TBSCERTIFICATE_F_PRESENT_EXT_KEY_USAGE RT_BIT_32(1)
#define RTCRX509TBSCERTIFICATE_F_PRESENT_SUBJECT_KEY_IDENTIFIER RT_BIT_32(2)
#define RTCRX509TBSCERTIFICATE_F_PRESENT_SUBJECT_ALT_NAME RT_BIT_32(3)
#define RTCRX509TBSCERTIFICATE_F_PRESENT_ISSUER_ALT_NAME RT_BIT_32(4)
#define RTCRX509TBSCERTIFICATE_F_PRESENT_CERTIFICATE_POLICIES RT_BIT_32(5)
#define RTCRX509TBSCERTIFICATE_F_PRESENT_POLICY_MAPPINGS RT_BIT_32(6)
#define RTCRX509TBSCERTIFICATE_F_PRESENT_BASIC_CONSTRAINTS RT_BIT_32(7)
#define RTCRX509TBSCERTIFICATE_F_PRESENT_NAME_CONSTRAINTS RT_BIT_32(8)
#define RTCRX509TBSCERTIFICATE_F_PRESENT_POLICY_CONSTRAINTS RT_BIT_32(9)
#define RTCRX509TBSCERTIFICATE_F_PRESENT_AUTHORITY_KEY_IDENTIFIER RT_BIT_32(10)
#define RTCRX509TBSCERTIFICATE_F_PRESENT_OLD_AUTHORITY_KEY_IDENTIFIER RT_BIT_32(11)
#define RTCRX509TBSCERTIFICATE_F_PRESENT_ACCEPTABLE_CERT_POLICIES RT_BIT_32(12)
#define RTCRX509TBSCERTIFICATE_F_PRESENT_INHIBIT_ANY_POLICY RT_BIT_32(13)
#define RTCRX509TBSCERTIFICATE_F_PRESENT_OTHER RT_BIT_32(22) /**< Other unknown extension present. */
#define RTCRX509TBSCERTIFICATE_F_PRESENT_NONE RT_BIT_32(23) /**< No extensions present. */
/** @} */
/** @name X.509 Key Usage flags. (RFC-5280 section 4.2.1.3.)
* @{ */
#define RTCRX509CERT_KEY_USAGE_F_DIGITAL_SIGNATURE_BIT 0
#define RTCRX509CERT_KEY_USAGE_F_DIGITAL_SIGNATURE RT_BIT_32(0)
#define RTCRX509CERT_KEY_USAGE_F_CONTENT_COMMITTMENT_BIT 1
#define RTCRX509CERT_KEY_USAGE_F_CONTENT_COMMITTMENT RT_BIT_32(1)
#define RTCRX509CERT_KEY_USAGE_F_KEY_ENCIPHERMENT_BIT 2
#define RTCRX509CERT_KEY_USAGE_F_KEY_ENCIPHERMENT RT_BIT_32(2)
#define RTCRX509CERT_KEY_USAGE_F_DATA_ENCIPHERMENT_BIT 3
#define RTCRX509CERT_KEY_USAGE_F_DATA_ENCIPHERMENT RT_BIT_32(3)
#define RTCRX509CERT_KEY_USAGE_F_KEY_AGREEMENT_BIT 4
#define RTCRX509CERT_KEY_USAGE_F_KEY_AGREEMENT RT_BIT_32(4)
#define RTCRX509CERT_KEY_USAGE_F_KEY_CERT_SIGN_BIT 5
#define RTCRX509CERT_KEY_USAGE_F_KEY_CERT_SIGN RT_BIT_32(5)
#define RTCRX509CERT_KEY_USAGE_F_CRL_SIGN_BIT 6
#define RTCRX509CERT_KEY_USAGE_F_CRL_SIGN RT_BIT_32(6)
#define RTCRX509CERT_KEY_USAGE_F_ENCIPHERMENT_ONLY_BIT 7
#define RTCRX509CERT_KEY_USAGE_F_ENCIPHERMENT_ONLY RT_BIT_32(7)
#define RTCRX509CERT_KEY_USAGE_F_DECIPHERMENT_ONLY_BIT 8
#define RTCRX509CERT_KEY_USAGE_F_DECIPHERMENT_ONLY RT_BIT_32(8)
/** @} */
/** @name X.509 Extended Key Usage flags. (RFC-5280 section 4.2.1.12, ++.)
* @remarks Needless to say, these flags doesn't cover all possible extended key
* usages, because there is a potential unlimited number of them. Only
* ones relevant to IPRT and it's users are covered.
* @{ */
#define RTCRX509CERT_EKU_F_ANY RT_BIT_64(0)
#define RTCRX509CERT_EKU_F_SERVER_AUTH RT_BIT_64(1)
#define RTCRX509CERT_EKU_F_CLIENT_AUTH RT_BIT_64(2)
#define RTCRX509CERT_EKU_F_CODE_SIGNING RT_BIT_64(3)
#define RTCRX509CERT_EKU_F_EMAIL_PROTECTION RT_BIT_64(4)
#define RTCRX509CERT_EKU_F_IPSEC_END_SYSTEM RT_BIT_64(5)
#define RTCRX509CERT_EKU_F_IPSEC_TUNNEL RT_BIT_64(6)
#define RTCRX509CERT_EKU_F_IPSEC_USER RT_BIT_64(7)
#define RTCRX509CERT_EKU_F_TIMESTAMPING RT_BIT_64(8)
#define RTCRX509CERT_EKU_F_OCSP_SIGNING RT_BIT_64(9)
#define RTCRX509CERT_EKU_F_DVCS RT_BIT_64(10)
#define RTCRX509CERT_EKU_F_SBGP_CERT_AA_SERVICE_AUTH RT_BIT_64(11)
#define RTCRX509CERT_EKU_F_EAP_OVER_PPP RT_BIT_64(12)
#define RTCRX509CERT_EKU_F_EAP_OVER_LAN RT_BIT_64(13)
#define RTCRX509CERT_EKU_F_OTHER RT_BIT_64(16) /**< Other unknown extended key usage present. */
#define RTCRX509CERT_EKU_F_APPLE_CODE_SIGNING RT_BIT_64(24)
#define RTCRX509CERT_EKU_F_APPLE_CODE_SIGNING_DEVELOPMENT RT_BIT_64(25)
#define RTCRX509CERT_EKU_F_APPLE_SOFTWARE_UPDATE_SIGNING RT_BIT_64(26)
#define RTCRX509CERT_EKU_F_APPLE_CODE_SIGNING_THIRD_PARTY RT_BIT_64(27)
#define RTCRX509CERT_EKU_F_APPLE_RESOURCE_SIGNING RT_BIT_64(28)
#define RTCRX509CERT_EKU_F_APPLE_SYSTEM_IDENTITY RT_BIT_64(29)
#define RTCRX509CERT_EKU_F_MS_TIMESTAMP_SIGNING RT_BIT_64(32)
#define RTCRX509CERT_EKU_F_MS_NT5_CRYPTO RT_BIT_64(33)
#define RTCRX509CERT_EKU_F_MS_OEM_WHQL_CRYPTO RT_BIT_64(34)
#define RTCRX509CERT_EKU_F_MS_EMBEDDED_NT_CRYPTO RT_BIT_64(35)
#define RTCRX509CERT_EKU_F_MS_KERNEL_MODE_CODE_SIGNING RT_BIT_64(36)
#define RTCRX509CERT_EKU_F_MS_LIFETIME_SIGNING RT_BIT_64(37)
#define RTCRX509CERT_EKU_F_MS_DRM RT_BIT_64(38)
#define RTCRX509CERT_EKU_F_MS_DRM_INDIVIDUALIZATION RT_BIT_64(39)
#define RTCRX509CERT_EKU_F_MS_WHQL_CRYPTO RT_BIT_64(40)
#define RTCRX509CERT_EKU_F_MS_ATTEST_WHQL_CRYPTO RT_BIT_64(41)
/** @} */
/** @name Key purpose OIDs (extKeyUsage)
* @{ */
#define RTCRX509_ANY_EXTENDED_KEY_USAGE_OID "2.5.29.37.0"
#define RTCRX509_ID_KP_OID "1.3.6.1.5.5.7.3"
#define RTCRX509_ID_KP_SERVER_AUTH_OID "1.3.6.1.5.5.7.3.1"
#define RTCRX509_ID_KP_CLIENT_AUTH_OID "1.3.6.1.5.5.7.3.2"
#define RTCRX509_ID_KP_CODE_SIGNING_OID "1.3.6.1.5.5.7.3.3"
#define RTCRX509_ID_KP_EMAIL_PROTECTION_OID "1.3.6.1.5.5.7.3.4"
#define RTCRX509_ID_KP_IPSEC_END_SYSTEM_OID "1.3.6.1.5.5.7.3.5"
#define RTCRX509_ID_KP_IPSEC_TUNNEL_OID "1.3.6.1.5.5.7.3.6"
#define RTCRX509_ID_KP_IPSEC_USER_OID "1.3.6.1.5.5.7.3.7"
#define RTCRX509_ID_KP_TIMESTAMPING_OID "1.3.6.1.5.5.7.3.8"
#define RTCRX509_ID_KP_OCSP_SIGNING_OID "1.3.6.1.5.5.7.3.9"
#define RTCRX509_ID_KP_DVCS_OID "1.3.6.1.5.5.7.3.10"
#define RTCRX509_ID_KP_SBGP_CERT_AA_SERVICE_AUTH_OID "1.3.6.1.5.5.7.3.11"
#define RTCRX509_ID_KP_EAP_OVER_PPP_OID "1.3.6.1.5.5.7.3.13"
#define RTCRX509_ID_KP_EAP_OVER_LAN_OID "1.3.6.1.5.5.7.3.14"
/** @} */
/** @name Microsoft extended key usage OIDs
* @{ */
#define RTCRX509_MS_EKU_CERT_TRUST_LIST_SIGNING_OID "1.3.6.1.4.1.311.10.3.1"
#define RTCRX509_MS_EKU_TIMESTAMP_SIGNING_OID "1.3.6.1.4.1.311.10.3.2"
#define RTCRX509_MS_EKU_SERVER_GATED_CRYPTO_OID "1.3.6.1.4.1.311.10.3.3"
#define RTCRX509_MS_EKU_SGC_SERIALIZED_OID "1.3.6.1.4.1.311.10.3.3.1"
#define RTCRX509_MS_EKU_ENCRYPTED_FILE_SYSTEM_OID "1.3.6.1.4.1.311.10.3.4"
#define RTCRX509_MS_EKU_WHQL_CRYPTO_OID "1.3.6.1.4.1.311.10.3.5"
#define RTCRX509_MS_EKU_ATTEST_WHQL_CRYPTO_OID "1.3.6.1.4.1.311.10.3.5.1"
#define RTCRX509_MS_EKU_NT5_CRYPTO_OID "1.3.6.1.4.1.311.10.3.6"
#define RTCRX509_MS_EKU_OEM_WHQL_CRYPTO_OID "1.3.6.1.4.1.311.10.3.7"
#define RTCRX509_MS_EKU_EMBEDDED_NT_CRYPTO_OID "1.3.6.1.4.1.311.10.3.8"
#define RTCRX509_MS_EKU_ROOT_LIST_SIGNER_OID "1.3.6.1.4.1.311.10.3.9"
#define RTCRX509_MS_EKU_QUALIFIED_SUBORDINATE_OID "1.3.6.1.4.1.311.10.3.10"
#define RTCRX509_MS_EKU_KEY_RECOVERY_3_OID "1.3.6.1.4.1.311.10.3.11"
#define RTCRX509_MS_EKU_DOCUMENT_SIGNING_OID "1.3.6.1.4.1.311.10.3.12"
#define RTCRX509_MS_EKU_LIFETIME_SIGNING_OID "1.3.6.1.4.1.311.10.3.13"
#define RTCRX509_MS_EKU_MOBILE_DEVICE_SOFTWARE_OID "1.3.6.1.4.1.311.10.3.14"
#define RTCRX509_MS_EKU_SMART_DISPLAY_OID "1.3.6.1.4.1.311.10.3.15"
#define RTCRX509_MS_EKU_CSP_SIGNATURE_OID "1.3.6.1.4.1.311.10.3.16"
#define RTCRX509_MS_EKU_EFS_RECOVERY_OID "1.3.6.1.4.1.311.10.3.4.1"
#define RTCRX509_MS_EKU_DRM_OID "1.3.6.1.4.1.311.10.5.1"
#define RTCRX509_MS_EKU_DRM_INDIVIDUALIZATION_OID "1.3.6.1.4.1.311.10.5.2"
#define RTCRX509_MS_EKU_LICENSES_OID "1.3.6.1.4.1.311.10.5.3"
#define RTCRX509_MS_EKU_LICENSE_SERVER_OID "1.3.6.1.4.1.311.10.5.4"
#define RTCRX509_MS_EKU_ENROLLMENT_AGENT_OID "1.3.6.1.4.1.311.20.2.1"
#define RTCRX509_MS_EKU_SMARTCARD_LOGON_OID "1.3.6.1.4.1.311.20.2.2"
#define RTCRX509_MS_EKU_CA_EXCHANGE_OID "1.3.6.1.4.1.311.21.5"
#define RTCRX509_MS_EKU_KEY_RECOVERY_21_OID "1.3.6.1.4.1.311.21.6"
#define RTCRX509_MS_EKU_SYSTEM_HEALTH_OID "1.3.6.1.4.1.311.47.1.1"
#define RTCRX509_MS_EKU_SYSTEM_HEALTH_LOOPHOLE_OID "1.3.6.1.4.1.311.47.1.3"
#define RTCRX509_MS_EKU_KERNEL_MODE_CODE_SIGNING_OID "1.3.6.1.4.1.311.61.1.1"
/** @} */
/** @name Apple extended key usage OIDs
* @{ */
#define RTCRX509_APPLE_EKU_APPLE_EXTENDED_KEY_USAGE_OID "1.2.840.113635.100.4"
#define RTCRX509_APPLE_EKU_CODE_SIGNING_OID "1.2.840.113635.100.4.1"
#define RTCRX509_APPLE_EKU_CODE_SIGNING_DEVELOPMENT_OID "1.2.840.113635.100.4.1.1"
#define RTCRX509_APPLE_EKU_SOFTWARE_UPDATE_SIGNING_OID "1.2.840.113635.100.4.1.2"
#define RTCRX509_APPLE_EKU_CODE_SIGNING_THRID_PARTY_OID "1.2.840.113635.100.4.1.3"
#define RTCRX509_APPLE_EKU_RESOURCE_SIGNING_OID "1.2.840.113635.100.4.1.4"
#define RTCRX509_APPLE_EKU_ICHAT_SIGNING_OID "1.2.840.113635.100.4.2"
#define RTCRX509_APPLE_EKU_ICHAT_ENCRYPTION_OID "1.2.840.113635.100.4.3"
#define RTCRX509_APPLE_EKU_SYSTEM_IDENTITY_OID "1.2.840.113635.100.4.4"
#define RTCRX509_APPLE_EKU_CRYPTO_ENV_OID "1.2.840.113635.100.4.5"
#define RTCRX509_APPLE_EKU_CRYPTO_PRODUCTION_ENV_OID "1.2.840.113635.100.4.5.1"
#define RTCRX509_APPLE_EKU_CRYPTO_MAINTENANCE_ENV_OID "1.2.840.113635.100.4.5.2"
#define RTCRX509_APPLE_EKU_CRYPTO_TEST_ENV_OID "1.2.840.113635.100.4.5.3"
#define RTCRX509_APPLE_EKU_CRYPTO_DEVELOPMENT_ENV_OID "1.2.840.113635.100.4.5.4"
#define RTCRX509_APPLE_EKU_CRYPTO_QOS_OID "1.2.840.113635.100.4.6"
#define RTCRX509_APPLE_EKU_CRYPTO_TIER0_QOS_OID "1.2.840.113635.100.4.6.1"
#define RTCRX509_APPLE_EKU_CRYPTO_TIER1_QOS_OID "1.2.840.113635.100.4.6.2"
#define RTCRX509_APPLE_EKU_CRYPTO_TIER2_QOS_OID "1.2.840.113635.100.4.6.3"
#define RTCRX509_APPLE_EKU_CRYPTO_TIER3_QOS_OID "1.2.840.113635.100.4.6.4"
/** @} */
/**
* Use this to update derived values after changing the certificate
* extensions.
*
* @returns IPRT status code
* @param pThis The certificate.
* @param pErrInfo Where to return additional error information. Optional.
*/
RTDECL(int) RTCrX509TbsCertificate_ReprocessExtensions(PRTCRX509TBSCERTIFICATE pThis, PRTERRINFO pErrInfo);
/**
* One X.509 Certificate (IPRT representation).
*/
typedef struct RTCRX509CERTIFICATE
{
/** Sequence core. */
RTASN1SEQUENCECORE SeqCore;
/** The to-be-signed certificate information. */
RTCRX509TBSCERTIFICATE TbsCertificate;
/** The signature algorithm (must match TbsCertificate.Signature). */
RTCRX509ALGORITHMIDENTIFIER SignatureAlgorithm;
/** The signature value. */
RTASN1BITSTRING SignatureValue;
} RTCRX509CERTIFICATE;
/** Pointer to the IPRT representation of one X.509 certificate. */
typedef RTCRX509CERTIFICATE *PRTCRX509CERTIFICATE;
/** Pointer to the const IPRT representation of one X.509 certificate. */
typedef RTCRX509CERTIFICATE const *PCRTCRX509CERTIFICATE;
RTASN1TYPE_STANDARD_PROTOTYPES(RTCRX509CERTIFICATE, RTDECL, RTCrX509Certificate, SeqCore.Asn1Core);
/**
* Checks if a certificate matches a given issuer name and serial number.
*
* @returns True / false.
* @param pCertificate The X.509 certificat.
* @param pIssuer The issuer name to match against.
* @param pSerialNumber The serial number to match against.
*/
RTDECL(bool) RTCrX509Certificate_MatchIssuerAndSerialNumber(PCRTCRX509CERTIFICATE pCertificate,
PCRTCRX509NAME pIssuer, PCRTASN1INTEGER pSerialNumber);
RTDECL(bool) RTCrX509Certificate_MatchSubjectOrAltSubjectByRfc5280(PCRTCRX509CERTIFICATE pThis, PCRTCRX509NAME pName);
RTDECL(bool) RTCrX509Certificate_IsSelfSigned(PCRTCRX509CERTIFICATE pCertificate);
RTDECL(int) RTCrX509Certificate_VerifySignature(PCRTCRX509CERTIFICATE pThis, PCRTASN1OBJID pAlgorithm,
PCRTASN1DYNTYPE pParameters, PCRTASN1BITSTRING pPublicKey,
PRTERRINFO pErrInfo);
RTDECL(int) RTCrX509Certificate_VerifySignatureSelfSigned(PCRTCRX509CERTIFICATE pThis, PRTERRINFO pErrInfo);
RTDECL(int) RTCrX509Certificate_ReadFromFile(PRTCRX509CERTIFICATE pCertificate, const char *pszFilename, uint32_t fFlags,
PCRTASN1ALLOCATORVTABLE pAllocator, PRTERRINFO pErrInfo);
RTDECL(int) RTCrX509Certificate_ReadFromBuffer(PRTCRX509CERTIFICATE pCertificate, const void *pvBuf, size_t cbBuf,
uint32_t fFlags, PCRTASN1ALLOCATORVTABLE pAllocator,
PRTERRINFO pErrInfo, const char *pszErrorTag);
/** @name Flags for RTCrX509Certificate_ReadFromFile and
* RTCrX509Certificate_ReadFromBuffer
* @{ */
/** Only allow PEM certificates, not binary ones.
* @sa RTCRPEMREADFILE_F_ONLY_PEM */
#define RTCRX509CERT_READ_F_PEM_ONLY RT_BIT(1)
/** @} */
/** X509 Certificate markers for RTCrPemFindFirstSectionInContent et al. */
extern RTDATADECL(RTCRPEMMARKER const) g_aRTCrX509CertificateMarkers[];
/** Number of entries in g_aRTCrX509CertificateMarkers. */
extern RTDATADECL(uint32_t const) g_cRTCrX509CertificateMarkers;
/** Wrapper around RTCrPemWriteAsn1ToVfsIoStrm(). */
DECLINLINE(ssize_t) RTCrX509Certificate_WriteToVfsIoStrm(RTVFSIOSTREAM hVfsIos, PRTCRX509CERTIFICATE pCertificate,
PRTERRINFO pErrInfo)
{
return RTCrPemWriteAsn1ToVfsIoStrm(hVfsIos, &pCertificate->SeqCore.Asn1Core, 0 /*fFlags*/,
g_aRTCrX509CertificateMarkers[0].paWords[0].pszWord, pErrInfo);
}
/** Wrapper around RTCrPemWriteAsn1ToVfsFile(). */
DECLINLINE(ssize_t) RTCrX509Certificate_WriteToVfsFile(RTVFSFILE hVfsFile, PRTCRX509CERTIFICATE pCertificate,
PRTERRINFO pErrInfo)
{
return RTCrPemWriteAsn1ToVfsFile(hVfsFile, &pCertificate->SeqCore.Asn1Core, 0 /*fFlags*/,
g_aRTCrX509CertificateMarkers[0].paWords[0].pszWord, pErrInfo);
}
/** @name X.509 Certificate Extensions
* @{ */
/** Old AuthorityKeyIdentifier OID. */
#define RTCRX509_ID_CE_OLD_AUTHORITY_KEY_IDENTIFIER_OID "2.5.29.1"
/** Old CertificatePolicies extension OID. */
#define RTCRX509_ID_CE_OLD_CERTIFICATE_POLICIES_OID "2.5.29.3"
/** Old SubjectAltName extension OID. */
#define RTCRX509_ID_CE_OLD_SUBJECT_ALT_NAME_OID "2.5.29.7"
/** Old IssuerAltName extension OID. */
#define RTCRX509_ID_CE_OLD_ISSUER_ALT_NAME_OID "2.5.29.8"
/** Old BasicContraints extension OID. */
#define RTCRX509_ID_CE_OLD_BASIC_CONSTRAINTS_OID "2.5.29.10"
/** SubjectKeyIdentifier OID. */
#define RTCRX509_ID_CE_SUBJECT_KEY_IDENTIFIER_OID "2.5.29.14"
/** KeyUsage OID. */
#define RTCRX509_ID_CE_KEY_USAGE_OID "2.5.29.15"
/** PrivateKeyUsagePeriod OID. */
#define RTCRX509_ID_CE_PRIVATE_KEY_USAGE_PERIOD_OID "2.5.29.16"
/** SubjectAltName extension OID. */
#define RTCRX509_ID_CE_SUBJECT_ALT_NAME_OID "2.5.29.17"
/** IssuerAltName extension OID. */
#define RTCRX509_ID_CE_ISSUER_ALT_NAME_OID "2.5.29.18"
/** BasicContraints extension OID. */
#define RTCRX509_ID_CE_BASIC_CONSTRAINTS_OID "2.5.29.19"
/** NameContraints extension OID. */
#define RTCRX509_ID_CE_NAME_CONSTRAINTS_OID "2.5.29.30"
/** CertificatePolicies extension OID. */
#define RTCRX509_ID_CE_CERTIFICATE_POLICIES_OID "2.5.29.32"
/** PolicyMappings extension OID. */
#define RTCRX509_ID_CE_POLICY_MAPPINGS_OID "2.5.29.33"
/** AuthorityKeyIdentifier OID. */
#define RTCRX509_ID_CE_AUTHORITY_KEY_IDENTIFIER_OID "2.5.29.35"
/** PolicyContraints extension OID. */
#define RTCRX509_ID_CE_POLICY_CONSTRAINTS_OID "2.5.29.36"
/** ExtKeyUsage (extended key usage) extension OID. */
#define RTCRX509_ID_CE_EXT_KEY_USAGE_OID "2.5.29.37"
/** ExtKeyUsage: OID for permitting any unspecified key usage. */
#define RTCRX509_ID_CE_ANY_EXTENDED_KEY_USAGE_OID "2.5.29.37.0"
/** AuthorityAttributeIdentifier OID. */
#define RTCRX509_ID_CE_AUTHORITY_ATTRIBUTE_IDENTIFIER_OID "2.5.29.38"
/** AcceptableCertPolicies OID. */
#define RTCRX509_ID_CE_ACCEPTABLE_CERT_POLICIES_OID "2.5.29.52"
/** InhibitAnyPolicy OID. */
#define RTCRX509_ID_CE_INHIBIT_ANY_POLICY_OID "2.5.29.54"
/** @} */
/*
* Sequence of X.509 Certifcates (IPRT representation).
*/
RTASN1_IMPL_GEN_SET_OF_TYPEDEFS_AND_PROTOS(RTCRX509CERTIFICATES, RTCRX509CERTIFICATE, RTDECL, RTCrX509Certificates);
/**
* Looks up a certificate by issuer name and serial number.
*
* @returns Pointer to the given certificate if found, NULL if not.
* @param pCertificates The X.509 certificate set to search.
* @param pIssuer The issuer name of the wanted certificate.
* @param pSerialNumber The serial number of the wanted certificate.
*/
RTDECL(PCRTCRX509CERTIFICATE) RTCrX509Certificates_FindByIssuerAndSerialNumber(PCRTCRX509CERTIFICATES pCertificates,
PCRTCRX509NAME pIssuer,
PCRTASN1INTEGER pSerialNumber);
RTDECL(int) RTCrX509CertPathsCreate(PRTCRX509CERTPATHS phCertPaths, PCRTCRX509CERTIFICATE pTarget);
RTDECL(uint32_t) RTCrX509CertPathsRetain(RTCRX509CERTPATHS hCertPaths);
RTDECL(uint32_t) RTCrX509CertPathsRelease(RTCRX509CERTPATHS hCertPaths);
RTDECL(int) RTCrX509CertPathsSetTrustedStore(RTCRX509CERTPATHS hCertPaths, RTCRSTORE hTrustedStore);
RTDECL(int) RTCrX509CertPathsSetUntrustedStore(RTCRX509CERTPATHS hCertPaths, RTCRSTORE hUntrustedStore);
RTDECL(int) RTCrX509CertPathsSetUntrustedArray(RTCRX509CERTPATHS hCertPaths, PCRTCRX509CERTIFICATE paCerts, uint32_t cCerts);
RTDECL(int) RTCrX509CertPathsSetUntrustedSet(RTCRX509CERTPATHS hCertPaths, struct RTCRPKCS7SETOFCERTS const *pSetOfCerts);
RTDECL(int) RTCrX509CertPathsSetValidTime(RTCRX509CERTPATHS hCertPaths, PCRTTIME pTime);
RTDECL(int) RTCrX509CertPathsSetValidTimeSpec(RTCRX509CERTPATHS hCertPaths, PCRTTIMESPEC pTimeSpec);
RTDECL(int) RTCrX509CertPathsSetTrustAnchorChecks(RTCRX509CERTPATHS hCertPaths, bool fEnable);
RTDECL(int) RTCrX509CertPathsCreateEx(PRTCRX509CERTPATHS phCertPaths, PCRTCRX509CERTIFICATE pTarget, RTCRSTORE hTrustedStore,
RTCRSTORE hUntrustedStore, PCRTCRX509CERTIFICATE paUntrustedCerts, uint32_t cUntrustedCerts,
PCRTTIMESPEC pValidTime);
RTDECL(int) RTCrX509CertPathsBuild(RTCRX509CERTPATHS hCertPaths, PRTERRINFO pErrInfo);
RTDECL(int) RTCrX509CertPathsDumpOne(RTCRX509CERTPATHS hCertPaths, uint32_t iPath, uint32_t uVerbosity,
PFNRTDUMPPRINTFV pfnPrintfV, void *pvUser);
RTDECL(int) RTCrX509CertPathsDumpAll(RTCRX509CERTPATHS hCertPaths, uint32_t uVerbosity,
PFNRTDUMPPRINTFV pfnPrintfV, void *pvUser);
RTDECL(int) RTCrX509CertPathsValidateOne(RTCRX509CERTPATHS hCertPaths, uint32_t iPath, PRTERRINFO pErrInfo);
RTDECL(int) RTCrX509CertPathsValidateAll(RTCRX509CERTPATHS hCertPaths, uint32_t *pcValidPaths, PRTERRINFO pErrInfo);
RTDECL(uint32_t) RTCrX509CertPathsGetPathCount(RTCRX509CERTPATHS hCertPaths);
RTDECL(int) RTCrX509CertPathsQueryPathInfo(RTCRX509CERTPATHS hCertPaths, uint32_t iPath,
bool *pfTrusted, uint32_t *pcNodes, PCRTCRX509NAME *ppSubject,
PCRTCRX509SUBJECTPUBLICKEYINFO *ppPublicKeyInfo,
PCRTCRX509CERTIFICATE *ppCert, PCRTCRCERTCTX *ppCertCtx, int *prcVerify);
RTDECL(uint32_t) RTCrX509CertPathsGetPathLength(RTCRX509CERTPATHS hCertPaths, uint32_t iPath);
RTDECL(int) RTCrX509CertPathsGetPathVerifyResult(RTCRX509CERTPATHS hCertPaths, uint32_t iPath);
RTDECL(PCRTCRX509CERTIFICATE) RTCrX509CertPathsGetPathNodeCert(RTCRX509CERTPATHS hCertPaths, uint32_t iPath, uint32_t iNode);
/**
* Generates a self-signed RSA certificate, storing the result as two file.
*
* @note The private key will be stored unencrypted!
*
* @returns IPRT status code.
* @param enmDigestType The digest type to use when signing.
* @param cBits The private key size (in bits).
* @param cSecsValidFor Number of seconds the certificate should be
* valid for (starting now).
* @param fKeyUsage Key usage mask: RTCRX509CERT_KEY_USAGE_F_XXX.
* @param fExtKeyUsage Extended key usage mask: RTCRX509CERT_EKU_F_XXX.
* @param pvSubject Subject name.
* @param pszCertFile Where to store the certificate (PEM formatting).
* @param pszPrivateKeyFile Where to store the unencrypted private key (PEM
* formatting).
* @param pErrInfo Where to return extended error information.
* Optional.
*/
RTDECL(int) RTCrX509Certificate_GenerateSelfSignedRsa(RTDIGESTTYPE enmDigestType, uint32_t cBits, uint32_t cSecsValidFor,
uint32_t fKeyUsage, uint64_t fExtKeyUsage, const char *pvSubject,
const char *pszCertFile, const char *pszPrivateKeyFile, PRTERRINFO pErrInfo);
RT_C_DECLS_END
/** @} */
/** @} */
#endif /* !IPRT_INCLUDED_crypto_x509_h */
|