Skip to content

Commit 069640b

Browse files
committed
fix(rust/c509-certificate): update docs
1 parent 0e30d15 commit 069640b

File tree

19 files changed

+53
-68
lines changed

19 files changed

+53
-68
lines changed
Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; This c509 Certificate format is based upon:
2-
; https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/09/
2+
; https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/11/
33
; And is restricted/customized to better enable compatibility with Plutus scripts
44
; that would consume them, without loosing necessary features of x509
55
; Not all x509 features are supported and some fields have different semantics to improve
@@ -11,42 +11,32 @@ C509CertificatePlutusRestrictedSubset = [ TBSCertificate, issuerSignatureValue:
1111

1212
; The elements of the following group are used in a CBOR Sequence:
1313
TBSCertificate = (
14-
c509CertificateType: &c509CertificateTypeValues, ; Always 0
14+
c509CertificateType: int, ; Always 2 as natively signed C509 certificate following X.509 v3
1515
certificateSerialNumber: CertificateSerialNumber, ; Can be ignored/set to 0 or used as intended.
16-
issuer: Name, ; This could be an on-chain reference to the issuer cert, what would be the best way? Transaction hash/cert hash?
17-
validityNotBefore: Time, ; c509 uses UTC
18-
validityNotAfter: Time, ; c509 uses UTC
16+
issuerSignatureAlgorithm: AlgorithmIdentifier, ; Must be int(12) = Ed25519
17+
issuer: Name / null, ; If set to null, use the `subject`. This could be an on-chain reference to
18+
the issuer cert, what would be the best way? Transaction hash/cert hash?
19+
validityNotBefore: ~time, ; UTC
20+
validityNotAfter: ~time / null, ; UTC
1921
subject: Name, ; Reference to on-chain keys related to this certificate
2022
subjectPublicKeyAlgorithm: AlgorithmIdentifier, ; Must be int(12) = Ed25519
21-
subjectPublicKey: subjectPublicKey, ; Ed25519 public key
22-
extensions: Extensions, ; No extensions are currently supported must be set to []
23-
issuerSignatureAlgorithm: AlgorithmIdentifier, ; Must be int(12) = Ed25519
24-
)
25-
26-
; 0 = Native CBOR Certificate type
27-
; 1 = reencoded-der-cert - Not supported in this restricted version of the format.
28-
c509CertificateTypeValues = ( native-cbor: 0,
29-
; reencoded-der: 1 ; Not supported in this restricted encoding format
23+
subjectPublicKey: any, ; Ed25519 public key
24+
extensions: Extensions, ; Currently support extensions with basic CBOR types and Alternative Name
3025
)
3126

32-
CertificateSerialNumber = biguint
33-
34-
Name = [ * RelativeDistinguishedName ]
35-
/ text
36-
/ bytes
27+
CertificateSerialNumber = ~biguint
3728

38-
RelativeDistinguishedName = Attribute / [ 2* Attribute ]
29+
Name = [ * Attribute ] / text / bytes
3930

4031
Attribute = (
4132
( attributeType: int, attributeValue: text )
4233
// ( attributeType: oid, attributeValue: bytes )
43-
// ( attributeType: pen, attributeValue: bytes )
4434
// CardanoPublicKey
4535
)
4636

4737
subjectPublicKey = bytes .size (32..32); Ed25519 public key stored in bytes, adjust size of this if other key types are supported.
4838

49-
; This is a completely custom Attribute for the RelativeDistinguishedName which is only for use with Plutus scripts.
39+
; This is a completely custom Attribute, which is only for use with Plutus scripts.
5040
; attributeType = The type of Cardano key we associate with this certificate.
5141
; proof = Does the transaction require proof that the key is owned by the transaction signer?
5242
; attributeValue = The Cardano public key hash of the attribute type
@@ -61,14 +51,12 @@ cardanoKeyTypes = (
6151
ccHotVerificationKeyHash: 4,
6252
)
6353

64-
; Plutus will need to convert the Unix epoch timestamp to the nearest slot number
54+
; For `~time` Plutus will need to convert the Unix epoch timestamp to the nearest slot number
6555
; validityNotBefore rounds up to the next Slot after that time.
6656
; validityNotAfter rounds down to the next Slot before that time.
67-
Time = ( ~time / null )
6857

6958
ed25519Signature = bstr .size 64; Ed25519 signature must be tagged to identify their type.
7059

71-
7260
; Currently ONLY AlgorithmIdentifier int(12) - Ed25519 is supported.
7361
; oid and [ algorithm: oid, parameters: bytes ] are not supported by Plutus.
7462
AlgorithmIdentifier = (int
@@ -82,5 +70,4 @@ Extensions = [ * Extension ] / int
8270
Extension = (
8371
( extensionID: int, extensionValue: any )
8472
// ( extensionID: ~oid, ? critical: true, extensionValue: bytes )
85-
// ( extensionID: pen, ? critical: true, extensionValue: bytes )
8673
)

rust/c509-certificate/examples/cli/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ struct C509Json {
115115
/// Optional validity not after date,
116116
/// if not provided, set to no expire date 9999-12-31T23:59:59+00:00.
117117
validity_not_after: Option<String>,
118-
/// Relative distinguished name of the subject.
118+
/// Attributes of the subject.
119119
subject: Attributes,
120120
/// Optional subject public key algorithm of the certificate,
121121
/// if not provided, set to Ed25519.
@@ -304,10 +304,10 @@ fn decode(file: &PathBuf, output: Option<PathBuf>) -> anyhow::Result<()> {
304304
certificate_type: Some(tbs_cert.get_c509_certificate_type()),
305305
serial_number: Some(tbs_cert.get_certificate_serial_number().clone()),
306306
issuer_signature_algorithm: Some(tbs_cert.get_issuer_signature_algorithm().clone()),
307-
issuer: Some(extract_relative_distinguished_name(tbs_cert.get_issuer())?),
307+
issuer: Some(extract_attributes(tbs_cert.get_issuer())?),
308308
validity_not_before: Some(time_to_string(tbs_cert.get_validity_not_before().to_u64())?),
309309
validity_not_after: Some(time_to_string(tbs_cert.get_validity_not_after().to_u64())?),
310-
subject: extract_relative_distinguished_name(tbs_cert.get_subject())?,
310+
subject: extract_attributes(tbs_cert.get_subject())?,
311311
subject_public_key_algorithm: Some(tbs_cert.get_subject_public_key_algorithm().clone()),
312312
// Return a hex formation of the public key
313313
subject_public_key: tbs_cert.get_subject_public_key().encode_hex(),
@@ -326,7 +326,7 @@ fn decode(file: &PathBuf, output: Option<PathBuf>) -> anyhow::Result<()> {
326326
}
327327

328328
/// Extract a `Attributes` from a `Name`.
329-
fn extract_relative_distinguished_name(name: &Name) -> anyhow::Result<Attributes> {
329+
fn extract_attributes(name: &Name) -> anyhow::Result<Attributes> {
330330
match name.get_value() {
331331
NameValue::Attributes(attrs) => Ok(attrs.clone()),
332332
_ => Err(anyhow::anyhow!("Expected Attributes")),

rust/c509-certificate/examples/web/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Testing the wasm binding JS functions.
22

33
import init, {
4-
generate,
5-
verify,
64
decode,
7-
PublicKey,
5+
generate,
86
PrivateKey,
7+
PublicKey,
8+
verify,
99
} from "../../pkg/c509_certificate.js";
1010

1111
const pem_sk = `
@@ -24,7 +24,7 @@ const tbs = {
2424
c509_certificate_type: 0,
2525
certificate_serial_number: 1000000n,
2626
issuer: {
27-
relative_distinguished_name: [
27+
attributes: [
2828
{
2929
oid: "2.5.4.3",
3030
value: [{ text: "RFC test CA" }],

rust/c509-certificate/src/algorithm_identifier.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! not implemented yet.
1212
//!
1313
//! For more information about `AlgorithmIdentifier`,
14-
//! visit [C509 Certificate](https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/09/)
14+
//! visit [C509 Certificate](https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/11/)
1515
1616
use asn1_rs::Oid;
1717
use minicbor::{encode::Write, Decode, Decoder, Encode, Encoder};

rust/c509-certificate/src/attributes/attribute.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
//!
33
//! ```cddl
44
//! Attribute = ( attributeType: int, attributeValue: text ) //
5-
//! ( attributeType: ~oid, attributeValue: bytes ) //
6-
//! ( attributeType: pen, attributeValue: bytes )
5+
//! ( attributeType: ~oid, attributeValue: bytes ) //
76
//! ```
87
//!
98
//! For more information about Attribute,
10-
//! visit [C509 Certificate](https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/09/)
9+
//! visit [C509 Certificate](https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/11/)
1110
1211
use std::str::FromStr;
1312

rust/c509-certificate/src/attributes/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Attribute data provides a necessary information for encoding and decoding of C509
2-
//! Attribute. See [C509 Certificate](https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/09/)
2+
//! Attribute. See [C509 Certificate](https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/11/)
33
//! Section 9.3 C509 Attributes Registry for more information.
44
55
use anyhow::Error;

rust/c509-certificate/src/attributes/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! ```cddl
44
//! Attributes = ( attributeType: int, attributeValue: [+text] ) //
5-
//! ( attributeType: ~oid, attributeValue: [+bytes] )
5+
//! ( attributeType: ~oid, attributeValue: [+bytes] )
66
//! ```
77
//!
88
//! Use case:
@@ -11,7 +11,7 @@
1111
//! ```
1212
//!
1313
//! For more information about `Attributes`,
14-
//! visit [C509 Certificate](https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/09/)
14+
//! visit [C509 Certificate](https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/11/)
1515
1616
use attribute::Attribute;
1717
use minicbor::{encode::Write, Decode, Decoder, Encode, Encoder};
@@ -59,7 +59,8 @@ impl Encode<()> for Attributes {
5959
"Attributes should not be empty",
6060
));
6161
}
62-
e.array(self.0.len() as u64)?;
62+
// The attribute type should be included in array too
63+
e.array(self.0.len() as u64 * 2)?;
6364
for attribute in &self.0 {
6465
attribute.encode(e, ctx)?;
6566
}
@@ -78,7 +79,8 @@ impl Decode<'_, ()> for Attributes {
7879

7980
let mut attributes = Attributes::new();
8081

81-
for _ in 0..len {
82+
// The attribute type is included in an array, so divide by 2
83+
for _ in 0..len / 2 {
8284
let attribute = Attribute::decode(d, &mut ())?;
8385
attributes.add_attr(attribute);
8486
}
@@ -108,13 +110,13 @@ mod test_attributes {
108110
attributes
109111
.encode(&mut encoder, &mut ())
110112
.expect("Failed to encode Attributes");
111-
// 1 Attribute value (array len 1): 0x81
113+
// 1 Attribute (array len 2 (attribute type + value)): 0x82
112114
// Email Address: 0x00
113115
// Attribute value (array len 2): 0x82
114116
// [email protected]: 0x736578616d706c65406578616d706c652e636f6d
115117
assert_eq!(
116118
hex::encode(buffer.clone()),
117-
"810082736578616d706c65406578616d706c652e636f6d736578616d706c65406578616d706c652e636f6d"
119+
"820082736578616d706c65406578616d706c652e636f6d736578616d706c65406578616d706c652e636f6d"
118120
);
119121

120122
let mut decoder = Decoder::new(&buffer);

rust/c509-certificate/src/big_uint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ mod test_big_uint {
5454

5555
use super::*;
5656

57-
// Test reference https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/09/
57+
// Test reference https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/11/
5858
// A.1. Example RFC 7925 profiled X.509 Certificate
5959
#[test]
6060
fn test_encode_decode() {
@@ -74,7 +74,7 @@ mod test_big_uint {
7474
assert_eq!(decoded_b_uint, b_uint);
7575
}
7676

77-
// Test reference https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/09/
77+
// Test reference https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/11/
7878
// A.2. Example IEEE 802.1AR profiled X.509 Certificate
7979
#[test]
8080
fn test_encode_decode_2() {

rust/c509-certificate/src/extensions/extension/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Extension data provides a necessary information for encoding and decoding of C509
2-
//! Extension. See [C509 Certificate](https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/09/)
2+
//! Extension. See [C509 Certificate](https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/11/)
33
//! Section 9.4 C509 Extensions Registry for more information.
44
55
// cspell: words Evt

rust/c509-certificate/src/extensions/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
//! C509 Extension as a part of `TBSCertificate` used in C509 Certificate.
22
//!
33
//! Extension fallback of C509 OID extension
4-
//! Given OID if not found in the registered OID table, it will be encoded as a PEN OID.
5-
//! If the OID is not a PEN OID, it will be encoded as an unwrapped OID.
4+
//! Given OID if not found in the registered OID table, it will be encoded as an unwrapped OID.
65
//!
76
//! ```cddl
87
//! Extensions and Extension can be encoded as the following:
98
//! Extensions = [ * Extension ] / int
109
//! Extension = ( extensionID: int, extensionValue: any ) //
11-
//! ( extensionID: ~oid, ? critical: true,
12-
//! extensionValue: bytes ) //
13-
//! ( extensionID: pen, ? critical: true,
14-
//! extensionValue: bytes )
10+
//! ( extensionID: ~oid, ? critical: true,
11+
//! extensionValue: bytes ) //
1512
//! ```
1613
//!
1714
//! For more information about Extensions,
18-
//! visit [C509 Certificate](https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/09/)
15+
//! visit [C509 Certificate](https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/11/)
1916
2017
pub mod alt_name;
2118
pub mod extension;

0 commit comments

Comments
 (0)