Comments (8)
Very nice! If you wanted to upstream a minimal version of the conversion code into this repo we'd happily accept it.
from swift-certificates.
Yes, this would be a really good bit of narrative documentation.
The reality is that it's just two steps: take the object from SecCertificateCopyData
, pass it to the Certificate(derEncoded:)
constructor. Everything should work well from there. But it'd be very valuable to add a piece of narrative documentation.
Even nicer might be to add a helper extension into the code that can do this directly. Something like:
#if canImport(Security)
import Security
extension SecCertificate {
public init(_ certificate: Certificate) throws {
// code here
}
}
extension Certificate {
public init(_ certificate: SecCertificate) throws {
// code here
}
}
#endif
That plus tests would be really nice. Are you interested in adding either?
from swift-certificates.
@Lukasa thanks for your response! I put it on my list :).
I already tried your approach:
import CryptoKit
import X509
import SwiftASN1
// 1. get the SecCertificate
var rawCert: SecCertificate!
SecIdentityCopyCertificate(identity, &rawCert)
// 2. pass it to the constructor
let certificate = Certificate(derData: SecCertificateCopyData(rawCert))
// 3. Causing an error
'CFData' is not convertible to 'String'
Using a as Data
and than a String(data:encoding)
was not helpful, too.
I know this is not a support platform, I just want to understand it - so I can contribute (and get my work done). :)
from swift-certificates.
Not convertible to String is a weird error. Similarly, derData
is not one of the constructors we offer.
Does this line work? let certificate = Certificate(derEncoded: SecCertificateCopyData(rawCert) as Data)
from swift-certificates.
Oh sorry, this is the right line:
let certificate = Certificate(derEncoded: Array(SecCertificateCopyData(rawCert) as Data))
from swift-certificates.
@Lukasa awesome! derData
was an autocompletion, maybe an hiccup because a property was named the same.
Thank you a lot for providing such an amazing lib. :)
from swift-certificates.
I will check if I'm capable of doing the implementation - but sadly not now. :)
from swift-certificates.
I'm making SwiftSecurity library for type-safe working with Apple Security
framework. My library supports storage of X509.Certificate
from current package in Keychain.
If you want to check, there is implementation of bridging between SecCertificate
and X509.Certificate
.
The final code syntax for developers:
import X509
import SwiftSecurity
// Create X.509 Certificate
let certificate = try Certificate(derRepresentation: certificateData)
// Get Data
certificate.derRepresentation /* Uses DER.Encoder() */
// Store X.509 Certificate in Keychain
try keychain.store(certificate, query: .certificate(for: "Root CA"))
// Retrieve from Keychain
let certificate: Certificate? = try keychain.retrieve(.certificate(for: "Root CA"))
from swift-certificates.
Related Issues (19)
- Add support for SecureEnclave.P256.Signing.PrivateKey HOT 4
- Generate SSL certificate that is signed by self signed Certificate Authority HOT 2
- swift-crypto didn't compile result in linker problem HOT 4
- Get data from public key HOT 7
- New API Proposal: PKCS#12 Support HOT 3
- Encodable/Decodable issues HOT 2
- Enter Certificate, Private Key to URLCredential, that may me do TLSHandshake HOT 1
- ambiguous codelink in OCSPPolicy.swift:71
- Linking fails in Xcode 15 when swift-certificates is used in a package that is linked to an application test target HOT 4
- SignedAttributes in CMSSignerInfo HOT 1
- Throw Leading or trailing line missing PEM discriminator HOT 4
- swift-certificate does not provide stable ABI HOT 7
- API Request: Encryption & Decryption for CMS HOT 1
- Can you support cocoapds HOT 1
- SecIdentity from PEM(s) HOT 2
- Information: Test `testCertificateDescription` fails on Mac platform HOT 2
- Case-insensitive identity verification
- Using `GeneralName.directoryName` results in a corrupt certificate HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-certificates.