Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CertificateRequest.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4
6{
10 public class CertificateRequest
11 {
12 private readonly SignatureAlgorithm signatureAlgorithm;
13 private string commonName = null; // 2.5.4.3 CN
14 private string surname = null; // 2.5.4.4
15 private string serialNumber = null; // 2.5.4.5
16 private string country = null; // 2.5.4.6 C
17 private string locality = null; // 2.5.4.7 L
18 private string stateOrProvince = null; // 2.5.4.8 ST
19 private string streetAddress = null; // 2.5.4.9
20 private string organization = null; // 2.5.4.10 O
21 private string organizationalUnit = null; // 2.5.4.11 OU
22 private string title = null; // 2.5.4.12
23 private string description = null; // 2.5.4.13
24 private string postalAddress = null; // 2.5.4.16
25 private string postalCode = null; // 2.5.4.17
26 private string postOfficeBox = null; // 2.5.4.18
27 private string physicalDeliveryOfficeName = null; // 2.5.4.19
28 private string telephoneNumber = null; // 2.5.4.20
29 private string registeredAddress = null; // 2.5.4.26
30 private string presentationAddress = null; // 2.5.4.29
31 private string name = null; // 2.5.4.41
32 private string givenName = null; // 2.5.4.42
33 private string initials = null; // 2.5.4.43
34 private string distinguishedName = null; // 2.5.4.49
35 private string houseIdentifier = null; // 2.5.4.51
36 private string[] subjectAlternativeNames = null; // 2.5.29.17
37 private string emailAddress = null; // 1.2.840.113549.1.9.1
38
44 {
45 this.signatureAlgorithm = SignatureAlgorithm;
46 }
47
51 public SignatureAlgorithm SignatureAlgorithm => this.signatureAlgorithm;
52
56 public string CommonName
57 {
58 get => this.commonName;
59 set => this.commonName = value;
60 }
61
65 public string Surname
66 {
67 get => this.surname;
68 set => this.surname = value;
69 }
70
74 public string SerialNumber
75 {
76 get => this.serialNumber;
77 set => this.serialNumber = value;
78 }
79
83 public string Country
84 {
85 get => this.country;
86 set => this.country = value;
87 }
88
92 public string Locality
93 {
94 get => this.locality;
95 set => this.locality = value;
96 }
97
101 public string StateOrProvince
102 {
103 get => this.stateOrProvince;
104 set => this.stateOrProvince = value;
105 }
106
110 public string StreetAddress
111 {
112 get => this.streetAddress;
113 set => this.streetAddress = value;
114 }
115
119 public string Organization
120 {
121 get => this.organization;
122 set => this.organization = value;
123 }
124
128 public string OrganizationalUnit
129 {
130 get => this.organizationalUnit;
131 set => this.organizationalUnit = value;
132 }
133
137 public string Title
138 {
139 get => this.title;
140 set => this.title = value;
141 }
142
146 public string Description
147 {
148 get => this.description;
149 set => this.description = value;
150 }
151
155 public string PostalAddress
156 {
157 get => this.postalAddress;
158 set => this.postalAddress = value;
159 }
160
164 public string PostalCode
165 {
166 get => this.postalCode;
167 set => this.postalCode = value;
168 }
169
173 public string PostOfficeBox
174 {
175 get => this.postOfficeBox;
176 set => this.postOfficeBox = value;
177 }
178
183 {
184 get => this.physicalDeliveryOfficeName;
185 set => this.physicalDeliveryOfficeName = value;
186 }
187
191 public string TelephoneNumber
192 {
193 get => this.telephoneNumber;
194 set => this.telephoneNumber = value;
195 }
196
200 public string RegisteredAddress
201 {
202 get => this.registeredAddress;
203 set => this.registeredAddress = value;
204 }
205
210 {
211 get => this.presentationAddress;
212 set => this.presentationAddress = value;
213 }
214
218 public string Name
219 {
220 get => this.name;
221 set => this.name = value;
222 }
223
227 public string GivenName
228 {
229 get => this.givenName;
230 set => this.givenName = value;
231 }
232
236 public string Initials
237 {
238 get => this.initials;
239 set => this.initials = value;
240 }
241
245 public string DistinguishedName
246 {
247 get => this.distinguishedName;
248 set => this.distinguishedName = value;
249 }
250
254 public string HouseIdentifier
255 {
256 get => this.houseIdentifier;
257 set => this.houseIdentifier = value;
258 }
259
264 {
265 get => this.subjectAlternativeNames;
266 set => this.subjectAlternativeNames = value;
267 }
268
272 public string EMailAddress
273 {
274 get => this.emailAddress;
275 set => this.emailAddress = value;
276 }
277
282 public byte[] BuildCSR()
283 {
284 DerEncoder DER = new DerEncoder();
285
286 DER.StartSEQUENCE(); // CertificationRequestInfo
287 DER.INTEGER(0); // Version
288
289 DER.StartSEQUENCE(); // subject
290 this.EncodeIfDefined(DER, "2.5.4.3", this.commonName);
291 this.EncodeIfDefined(DER, "2.5.4.4", this.surname);
292 this.EncodeIfDefined(DER, "2.5.4.5", this.serialNumber);
293 this.EncodeIfDefined(DER, "2.5.4.6", this.country);
294 this.EncodeIfDefined(DER, "2.5.4.7", this.locality);
295 this.EncodeIfDefined(DER, "2.5.4.8", this.stateOrProvince);
296 this.EncodeIfDefined(DER, "2.5.4.9", this.streetAddress);
297 this.EncodeIfDefined(DER, "2.5.4.10", this.organization);
298 this.EncodeIfDefined(DER, "2.5.4.11", this.organizationalUnit);
299 this.EncodeIfDefined(DER, "2.5.4.12", this.title);
300 this.EncodeIfDefined(DER, "2.5.4.13", this.description);
301 this.EncodeIfDefined(DER, "2.5.4.16", this.postalAddress);
302 this.EncodeIfDefined(DER, "2.5.4.17", this.postalCode);
303 this.EncodeIfDefined(DER, "2.5.4.18", this.postOfficeBox);
304 this.EncodeIfDefined(DER, "2.5.4.19", this.physicalDeliveryOfficeName);
305 this.EncodeIfDefined(DER, "2.5.4.20", this.telephoneNumber);
306 this.EncodeIfDefined(DER, "2.5.4.26", this.registeredAddress);
307 this.EncodeIfDefined(DER, "2.5.4.29", this.presentationAddress);
308 this.EncodeIfDefined(DER, "2.5.4.41", this.name);
309 this.EncodeIfDefined(DER, "2.5.4.42", this.givenName);
310 this.EncodeIfDefined(DER, "2.5.4.43", this.initials);
311 this.EncodeIfDefined(DER, "2.5.4.49", this.distinguishedName);
312 this.EncodeIfDefined(DER, "2.5.4.51", this.houseIdentifier);
313 this.EncodeIfDefined(DER, "1.2.840.113549.1.9.1", this.emailAddress);
314 DER.EndSEQUENCE(); // end of subject
315
316 DER.StartSEQUENCE(); // subjectPKInfo
317 DER.StartSEQUENCE(); // algorithm
318 DER.OBJECT_IDENTIFIER(this.signatureAlgorithm.PkiAlgorithmOID);
319 DER.NULL(); // No parameters
320 DER.EndSEQUENCE(); // end of algorithm
321 DER.StartBITSTRING(); // subjectPublicKey
322
323 this.signatureAlgorithm.ExportPublicKey(DER);
324
325 DER.EndBITSTRING(); // end of subjectPublicKey
326 DER.EndSEQUENCE(); // end of subjectPKInfo
327
328 DER.StartContent(Asn1TypeClass.ContextSpecific); // attributes
329
330 if (!(this.subjectAlternativeNames is null) && this.subjectAlternativeNames.Length > 0)
331 {
332 DER.StartSEQUENCE();
333 DER.OBJECT_IDENTIFIER("1.2.840.113549.1.9.14"); // extensionRequest
334 DER.StartSET();
335 DER.StartSEQUENCE();
336 DER.StartSEQUENCE();
337 DER.OBJECT_IDENTIFIER("2.5.29.17");
338 DER.StartOCTET_STRING();
339 DER.StartSEQUENCE();
340
341 foreach (string s in this.subjectAlternativeNames)
342 {
343 int Pos = DER.Position;
344 DER.IA5_STRING(s);
345 DER[Pos] = 0x82; // Encoded as Context-specific INTEGER...
346 }
347
348 DER.EndSEQUENCE();
349 DER.EndOCTET_STRING();
350 DER.EndSEQUENCE();
351 DER.EndSEQUENCE();
352 DER.EndSET();
353 DER.EndSEQUENCE();
354 }
355
356 DER.EndContent(Asn1TypeClass.ContextSpecific); // end of attributes
357 DER.EndSEQUENCE(); // end of CertificationRequestInfo
358
359 byte[] CertificationRequestInfo = DER.ToArray();
360
361 DER.Clear();
362 DER.StartSEQUENCE(); // CertificationRequest
363 DER.Raw(CertificationRequestInfo);
364
365 DER.StartSEQUENCE(); // signatureAlgorithm
366 DER.OBJECT_IDENTIFIER(this.signatureAlgorithm.HashAlgorithmOID);
367 DER.NULL(); // parameters
368 DER.EndSEQUENCE(); // End of signatureAlgorithm
369
370 DER.BITSTRING(this.signatureAlgorithm.Sign(CertificationRequestInfo)); // signature
371
372 DER.EndSEQUENCE(); // end of CertificationRequest
373
374 return DER.ToArray();
375 }
376
377 private void EncodeIfDefined(DerEncoder DER, string OID, string Value)
378 {
379 if (!(Value is null))
380 {
381 DER.StartSET();
382 DER.StartSEQUENCE();
383 DER.OBJECT_IDENTIFIER(OID);
384
385 if (DerEncoder.IsPrintable(Value))
386 DER.PRINTABLE_STRING(Value);
387 else
388 DER.IA5_STRING(Value);
389
390 DER.EndSEQUENCE();
391 DER.EndSET();
392 }
393 }
394
395 }
396}
Contains information about a Certificate Signing Request (CSR).
string DistinguishedName
Distinguished name (OID 2.5.4.49)
SignatureAlgorithm SignatureAlgorithm
Signature algorithm.
string PostalAddress
Postal Address (OID 2.5.4.16)
string TelephoneNumber
Telephone number (OID 2.5.4.20)
string StateOrProvince
Country Name (OID 2.5.4.8)
string PostOfficeBox
Post Office Box (OID 2.5.4.18)
string StreetAddress
Street Address (OID 2.5.4.9)
string PostalCode
Postal Code (OID 2.5.4.17)
string SerialNumber
Serial Number (OID 2.5.4.5)
string EMailAddress
e-Mail Address (OID 1.2.840.113549.1.9.1)
string PresentationAddress
Presentation Address (OID 2.5.4.29)
byte[] BuildCSR()
Building a Certificate Signing Request (CSR) in accordance with RFC 2986
string CommonName
Common Name (OID 2.5.4.3)
string GivenName
Given Name (OID 2.5.4.42)
string[] SubjectAlternativeNames
Subject Alternative Names (OID 2.5.29.17)
string Country
Country Name (OID 2.5.4.6)
string HouseIdentifier
House identifier (OID 2.5.4.51)
string Surname
Surname (OID 2.5.4.4)
string OrganizationalUnit
Organizational Unit Name (OID 2.5.4.11)
string Organization
Organization Name (OID 2.5.4.10)
string PhysicalDeliveryOfficeName
Physical Delivery Office Name (OID 2.5.4.19)
string Description
Description (OID 2.5.4.13)
string Locality
Locality Name (OID 2.5.4.7)
string Initials
Initials (OID 2.5.4.43)
string RegisteredAddress
Registered Address (OID 2.5.4.26)
CertificateRequest(SignatureAlgorithm SignatureAlgorithm)
Contains information about a Certificate Signing Request (CSR).
Encodes data using the Distinguished Encoding Rules (DER), as defined in X.690
Definition: DerEncoder.cs:40
void Raw(byte[] DerEncodedBytes)
Adds DER-encoded bytes to the output.
Definition: DerEncoder.cs:554
byte[] ToArray()
Converts the generated output to a byte arary.
Definition: DerEncoder.cs:72
void Clear()
Clears the output buffer.
Definition: DerEncoder.cs:62
void EndSET()
Ends the current SET.
Definition: DerEncoder.cs:517
void StartOCTET_STRING()
Starts a OCTET_STRING.
Definition: DerEncoder.cs:317
void StartBITSTRING()
Starts a BITSTRING.
Definition: DerEncoder.cs:290
void EndSEQUENCE()
Ends the current SEQUENCE.
Definition: DerEncoder.cs:483
void EndContent(Asn1TypeClass Class)
Ends the current Content section.
Definition: DerEncoder.cs:545
static bool IsPrintable(string Value)
Checks if a string is a printable string.
Definition: DerEncoder.cs:445
void OBJECT_IDENTIFIER(string OID)
Encodes an OBJECT IDENTIFIER value.
Definition: DerEncoder.cs:343
void NULL()
Encodes an NULL value.
Definition: DerEncoder.cs:333
void EndOCTET_STRING()
Ends the current OCTET_STRING.
Definition: DerEncoder.cs:325
void IA5_STRING(string Value)
Encodes an IA5 STRING value.
Definition: DerEncoder.cs:421
void BITSTRING(BitArray Bits)
Encodes an BITSTRING value.
Definition: DerEncoder.cs:235
void StartContent(Asn1TypeClass Class)
Starts a content section.
Definition: DerEncoder.cs:536
int Position
Current output position.
Definition: DerEncoder.cs:563
void INTEGER(long Value)
Encodes an INTEGER value.
Definition: DerEncoder.cs:99
void EndBITSTRING()
Ends the current BITSTRING.
Definition: DerEncoder.cs:299
void PRINTABLE_STRING(string Value)
Encodes an PRINTABLE STRING value.
Definition: DerEncoder.cs:431
void StartSET()
Starts a SET.
Definition: DerEncoder.cs:509
void StartSEQUENCE()
Starts a SEQUENCE.
Definition: DerEncoder.cs:465
Abstract base class for signature algorithms
Asn1TypeClass
Type class
Definition: DerEncoder.cs:14