Deep dive into the server and client implementation of the SurePack quantum-resistant certificate system
The SimpleEnroll function implements a secure certificate enrollment system that creates X.509 certificates signed by a Certificate Authority (CA). Here's a step-by-step breakdown of the process:
key
: An RSA 2048-bit public key in PEM formatdata
: Optional base64-encoded JSON data containing identity information and quantum-resistant keysThe system first validates the provided public key:
AsymmetricKeyParameter? publickeyRequestor = (AsymmetricKeyParameter)BouncyCastleHelper.fromPEM(key);
If the key is invalid or not in proper PEM format, the request is rejected.
The system supports two modes:
For identity verification:
GLOBALS.Anonymous
){origin}/tokens/{identity}.token
The system generates a unique three-word alias using a sophisticated algorithm:
word1-word2-word3.{origin}
(e.g., happy-cloud-tree.example.com
)The system retrieves the CA's private key for signing:
byte[] cakeysBytes = System.IO.File.ReadAllBytes($"subcakeys.{origin}.pem");
byte[] cakeysDecrypted = BouncyCastleHelper.DecryptWithKey(cakeysBytes, GLOBALS.password.ToBytes(), GLOBALS.origin.ToBytes());
The certificate is created with these specifications:
CN={alias}
(the three-word alias)CN={origin}
(the CA's domain)The signed certificate is stored in S3:
{origin}/cert/{alias}.pem
{origin}/identity/{identity}/{alias}.pem
The system returns:
The valid SSL certificate on the hosted domain is critically important for several reasons:
Trust Chain Establishment: The domain's SSL certificate establishes the initial trust relationship. When clients connect to retrieve certificates, they can verify they're talking to the legitimate certificate authority.
Man-in-the-Middle Protection: Without HTTPS secured by a valid SSL certificate, attackers could intercept certificate enrollment requests and issue fraudulent certificates.
Identity Verification: The domain in the SSL certificate becomes part of the certificate hierarchy. All issued certificates have the domain as their issuer, creating a verifiable chain of trust.
API Security: All API endpoints (enrollment, retrieval, verification) are protected by HTTPS, ensuring:
Token Protection: Identity verification tokens are transmitted over HTTPS, preventing interception and replay attacks.
Certificate Validation: The system includes a VerifyAliasAsync
method that retrieves and validates certificates over HTTPS. This process relies on the SSL certificate to ensure the validation request reaches the authentic CA.
The system essentially creates a two-tier PKI where:
This design allows the system to bootstrap trust from the web PKI into a custom PKI for secure communications, making the valid SSL certificate a fundamental security requirement.
The client-side certificate creation process is a sophisticated implementation that combines traditional RSA cryptography with quantum-resistant algorithms. Here's a step-by-step breakdown:
The client uses a command-line verb system:
[Verb("create", HelpText = "Create an alias.")]
Options include:
The client generates three different key pairs for comprehensive security:
AsymmetricCipherKeyPair keyPair = BouncyCastleHelper.GenerateKeyPair(2048);
AsymmetricCipherKeyPair KyberKeyPair = BouncyCastleQuantumHelper.GenerateKyberKeyPair();
AsymmetricCipherKeyPair DilithiumKeyPair = BouncyCastleQuantumHelper.GenerateDilithiumKeyPair();
The client creates a structured payload containing:
var data = new CustomExtensionData{
KyberKey = Convert.ToBase64String(KyberPublicKey),
DilithiumKey = Convert.ToBase64String(DilithiumPublicKey),
Email = opts.Email ?? string.Empty,
Token = opts.Token ?? string.Empty
};
This data is:
The client sends a POST request to the server's /simpleenroll
endpoint:
{
"key": "RSA public key in PEM format",
"data": "Base64-encoded JSON containing quantum keys and identity info"
}
The server returns:
The client stores all cryptographic materials securely:
Storage.StoreCert(alias, j.Certificate);
{alias}.pem
~/.local/share/surepack/aliases/
(Linux) or equivalentEach private key is encrypted before storage:
Storage.StorePrivateKey($"{alias}.rsa", privateKeyPem, Globals.Password);
Storage.StorePrivateKey($"{alias}.kyber", kyberPrivateKeyPem, Globals.Password);
Storage.StorePrivateKey($"{alias}.dilithium", dilithiumPrivateKeyPem, Globals.Password);
Encryption mechanism:
.rsa
, .kyber
, .dilithium
After receiving the certificate, the client immediately verifies it:
(bool valid, byte[] rootFingerprint) = await BouncyCastleHelper.VerifyAliasAsync(domain, alias, "");
This verification process:
string rootFingerprintHex = Convert.ToBase64String(rootFingerprint);
Storage.StorePrivateKey($"{alias}.root", rootFingerprintHex, Globals.Password);
The system implements a "belt and suspenders" approach:
This ensures security against both current and future (quantum) threats.
All private keys are generated locally on the client:
Private keys are encrypted using the user's password:
The client performs thorough validation:
~/.local/share/surepack/
├── aliases/
│ ├── {alias}.pem (certificate)
│ ├── {alias}.rsa (encrypted RSA private key)
│ ├── {alias}.kyber (encrypted Kyber private key)
│ ├── {alias}.dilithium (encrypted Dilithium private key)
│ └── {alias}.root (encrypted root fingerprint)
└── settings.json
From the client's perspective, the server's valid SSL certificate is crucial for:
Initial Trust Bootstrap: The HTTPS connection validates the server's identity before any certificate enrollment
Secure Key Transmission: The RSA public key and quantum public keys are transmitted over HTTPS, preventing interception
Token Security: Email verification tokens are protected during transmission
Certificate Retrieval: When verifying certificates, the client relies on HTTPS to ensure authentic CA certificates
Man-in-the-Middle Prevention: Without HTTPS, an attacker could intercept the enrollment request and issue fraudulent certificates
The client's VerifyAliasAsync
method specifically makes HTTPS calls to retrieve and validate certificates, making the SSL certificate a fundamental security requirement for the entire PKI system to function securely.
© 2024 Public Key Server Project | GitHub Repository