Giter VIP home page Giter VIP logo

Comments (8)

Lukasa avatar Lukasa commented on June 3, 2024 1

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.

Lukasa avatar Lukasa commented on June 3, 2024

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.

tscholze avatar tscholze commented on June 3, 2024

@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.

Lukasa avatar Lukasa commented on June 3, 2024

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.

Lukasa avatar Lukasa commented on June 3, 2024

Oh sorry, this is the right line:

let certificate = Certificate(derEncoded: Array(SecCertificateCopyData(rawCert) as Data))

from swift-certificates.

tscholze avatar tscholze commented on June 3, 2024

@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.

tscholze avatar tscholze commented on June 3, 2024

I will check if I'm capable of doing the implementation - but sadly not now. :)

from swift-certificates.

dm-zharov avatar dm-zharov commented on June 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.