Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X509Identity problems #267

Open
ondrejpazintelegrafia opened this issue Jan 19, 2024 · 2 comments
Open

X509Identity problems #267

ondrejpazintelegrafia opened this issue Jan 19, 2024 · 2 comments

Comments

@ondrejpazintelegrafia
Copy link

Hello.
Is it possible to use X509Identity as IUserIdentity to open ClientSessionChannel?

I want to use .pfx certificate to authentificate user. Is it possible to do?
Constructor X509Identity(X509Certificate certificate, RsaKeyParameters privateKey) has privateKey parameter. I don't have privateKey.

@awcullen
Copy link
Contributor

Today this software requires pem-encoded certificate and private key files.

You may be able to use openssl to convert a .pfx file to pem-encoded files.

@awcullen
Copy link
Contributor

You can also try code like this to load the .pfx file

// try load pfx.  pfx files can have password
{
    var x509Identity = default(X509Identity);
    var crtPassword = "password";
    var userCertInfo = new FileInfo(Path.Combine(pkiPath, "user", "certs", "ctt_usrT.pfx"));
    if (userCertInfo.Exists)
    {
        using (var crtStream = userCertInfo.OpenRead())
        {
            var store = new Pkcs12StoreBuilder().Build();
            store.Load(crtStream, crtPassword?.ToCharArray() ?? Array.Empty<char>());
            var alias = store.Aliases.First();
            var cert = store.GetCertificate(alias);
            var key = store.GetKey(alias);
            x509Identity = new X509Identity(cert.Certificate, key.Key as RsaKeyParameters);
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants