-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Ed25519 certificates
Motivation While Ed25519 is not available in the WebPKI, there are a number of contexts where it's an appropriate signature algorithm for X.509. In those contexts, we should allow the signature algorithm. Modifications Add support for Ed25519 keys and signatures. Add unit tests Result Ed25519 support in the X509 certs
- Loading branch information
Showing
10 changed files
with
352 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftCertificates open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the SwiftCertificates project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftCertificates project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Foundation | ||
import SwiftASN1 | ||
import Crypto | ||
|
||
extension Curve25519.Signing.PrivateKey { | ||
@inlinable | ||
init(pkcs8Key: PKCS8PrivateKey) throws { | ||
// Annoyingly, the PKCS8 key has the raw bytes wrapped inside an octet string. | ||
let rawRepresentation = try ASN1OctetString(derEncoded: pkcs8Key.privateKey.bytes) | ||
self = try .init(rawRepresentation: rawRepresentation.bytes) | ||
} | ||
|
||
@inlinable | ||
var derRepresentation: [UInt8] { | ||
// The DER representation we want is a PKCS8 private key. Somewhat annoyingly | ||
// for us, we have to wrap the key bytes in an extra layer of ASN1OctetString | ||
// which we encode separately. | ||
let pkcs8Key = PKCS8PrivateKey( | ||
algorithm: .ed25519, privateKey: ASN1OctetString(contentBytes: ArraySlice(self.rawRepresentation)) | ||
) | ||
var serializer = DER.Serializer() | ||
try! serializer.serialize(pkcs8Key) | ||
return serializer.serializedBytes | ||
} | ||
|
||
@inlinable | ||
var pemRepresentation: PEMDocument { | ||
return PEMDocument(type: "PRIVATE KEY", derBytes: self.derRepresentation) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.