ThalesGroup / crypto11

Implement crypto.Signer and crypto.Decrypter for HSM-protected keys via PKCS#11
MIT License
219 stars 86 forks source link

Using Client Certificate in IIS Server #98

Closed roberto497 closed 2 years ago

roberto497 commented 2 years ago

I have an api running on IIS, configured to accept client certificate, but the certificate is not being recognized when I send it through the code below:

`config := crypto11.Config{ Path: "C:\Windows\System32\aetpkss1.dll", TokenLabel: "TOKEN", Pin: "2903", }

context, err := crypto11.Configure(&config)
if err != nil {
    log.Fatalln(err)
}

certificates, err := context.FindAllPairedCertificates()
if err != nil {
    log.Fatalln(err)
}

fmt.Println("total certificates: ", len(certificates))

cert := certificates[0]

caCert, _ := ioutil.ReadFile("ca.crt")
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)

client := &http.Client{
    Transport: &http.Transport{
        TLSClientConfig: &tls.Config{
            Certificates:       []tls.Certificate{cert},
            Renegotiation:      tls.RenegotiateOnceAsClient,
            RootCAs:            caCertPool,
            InsecureSkipVerify: true,
        },
    },
}

req, err := http.NewRequest("GET", "https://192.168.15.38:9443/api/teste", nil)
if err != nil {
    log.Fatalln(err)
}

req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36")

resp, err := client.Do(req)
if err != nil {
    log.Fatalln(err)
}

fmt.Println("status code: ", resp.StatusCode)`

The strange thing is that if I send it through Python or Java or .net code, the certificate is recognized normally.