# Cannot add certificate to Cert:\\CurrentUser\\My

**URL:** https://travis-ci.community/t/cannot-add-certificate-to-cert-currentuser-my/5976
**Category:** Windows
**Created:** [November 15, 2019, 10:00pm UTC](https://travis-ci.community/t/cannot-add-certificate-to-cert-currentuser-my/5976 "2019-11-15T22:00:02Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![rvanmil](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/rvanmil/32/3150_2.png) [@rvanmil](https://travis-ci.community/u/rvanmil)
#### Post date: [November 15, 2019, 10:00pm UTC](https://travis-ci.community/t/cannot-add-certificate-to-cert-currentuser-my/5976/1 "2019-11-15T22:00:02Z")

</div>

VS2017 code signing (performed by a Cordova Windows build) expects the code signing certificate in `Cert:\CurrentUser\My`. Running this on a local machine works without problems, but on the Travis Windows environment it seems to be impossible because I cannot add the certificate to `Cert:\CurrentUser\My`.

I’ve tried adding the certificate in Travis with both certutil:

```
certutil -user -p mypassword -importpfx mycertificate.pfx

```

and with a powershell script:

```
Import-PfxCertificate -FilePath $Pfxpath -CertStoreLocation Cert:\CurrentUser\My -Password $Password

```

but both methods fail. It is possible to add the certificate to `Cert:\LocalMachine\My` but then VS2017 does not pick up the certificate and ends with a couple error messages.

```
warning APPX0105: Cannot import the key file 'mycertificate.pfx'. The key file may be password protected. To correct this, try to import the certificate manually into the current user's person al certificate store.
warning APPX0102: A certificate with thumbprint '1234567890123456789012345678901234567890' that is specified in the project cannot be found in the certificate store. Please specify a valid thumbprint in the project file.
warning APPX0107: The certificate specified is not valid for signing. For more information about valid certificates, see http://go.microsoft.com/fwlink/?LinkID=241478

```

Is there a way to fix this problem?

---

<div class="post-metadata">

### Author: ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)
#### Post date: [November 16, 2019, 9:30pm UTC](https://travis-ci.community/t/cannot-add-certificate-to-cert-currentuser-my/5976/2 "2019-11-16T21:30:10Z")

</div>

Please include a build link. Copypasting things here gives incomplete information.

---

<div class="post-metadata">

### Author: ![rvanmil](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/rvanmil/32/3150_2.png) [@rvanmil](https://travis-ci.community/u/rvanmil)
#### Post date: [November 17, 2019, 8:45am UTC](https://travis-ci.community/t/cannot-add-certificate-to-cert-currentuser-my/5976/3 "2019-11-17T08:45:46Z")

</div>

Sure, I understand. Give me some time to prepare a test case and I’ll share that over here.

---

<div class="post-metadata">

### Author: ![rvanmil](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/rvanmil/32/3150_2.png) [@rvanmil](https://travis-ci.community/u/rvanmil)
#### Post date: [November 18, 2019, 12:33pm UTC](https://travis-ci.community/t/cannot-add-certificate-to-cert-currentuser-my/5976/4 "2019-11-18T12:33:27Z")

</div>

As promised here is the test case and a couple build logs. In all cases the code signing step, or certificate import step fails.

Test case:

> **[rvanmil/travis-cordova-windows-test](https://github.com/rvanmil/travis-cordova-windows-test)**
>
> Travis Cordova Windows Code Signing Test. Contribute to rvanmil/travis-cordova-windows-test development by creating an account on GitHub.

Code signing fails, no certificate imported:  
[https://travis-ci.org/rvanmil/travis-cordova-windows-test/builds/613472656](https://travis-ci.org/rvanmil/travis-cordova-windows-test/builds/613472656)  
[https://api.travis-ci.org/v3/job/613472657/log.txt](https://api.travis-ci.org/v3/job/613472657/log.txt)

Code signing fails, certificate imported into LocalMachine:  
[https://travis-ci.org/rvanmil/travis-cordova-windows-test/builds/613476976](https://travis-ci.org/rvanmil/travis-cordova-windows-test/builds/613476976)  
[https://api.travis-ci.org/v3/job/613476977/log.txt](https://api.travis-ci.org/v3/job/613476977/log.txt)

Code signing fails, certificate import into CurrentUser fails (certutil):  
[https://travis-ci.org/rvanmil/travis-cordova-windows-test/builds/613478576](https://travis-ci.org/rvanmil/travis-cordova-windows-test/builds/613478576)  
[https://api.travis-ci.org/v3/job/613478577/log.txt](https://api.travis-ci.org/v3/job/613478577/log.txt)

Code signing fails, certificate import into CurrentUser fails (powershell):  
[https://travis-ci.org/rvanmil/travis-cordova-windows-test/builds/613479247](https://travis-ci.org/rvanmil/travis-cordova-windows-test/builds/613479247)  
[https://api.travis-ci.org/v3/job/613479248/log.txt](https://api.travis-ci.org/v3/job/613479248/log.txt)

---

<div class="post-metadata">

### Author: ![rvanmil](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/rvanmil/32/3150_2.png) [@rvanmil](https://travis-ci.community/u/rvanmil)
#### Post date: [December 2, 2019, 11:40am UTC](https://travis-ci.community/t/cannot-add-certificate-to-cert-currentuser-my/5976/5 "2019-12-02T11:40:40Z")

</div>

I got this to work with GitHub Actions, see here: [https://github.com/apache/cordova-windows/issues/354#issuecomment-559611332](https://github.com/apache/cordova-windows/issues/354#issuecomment-559611332)

---

<div class="post-metadata">

### Author: ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)
#### Post date: [December 5, 2019, 5:23pm UTC](https://travis-ci.community/t/cannot-add-certificate-to-cert-currentuser-my/5976/6 "2019-12-05T17:23:49Z")

</div>

Okay, this one took a while.

@BanzaiMan @kris[It looks like](https://travis-ci.community/t/linking-against-ncurses-no-package-from-chocolately-yet/1030/4)1 when preparing build VM’s image, you are cleaning out `AppData\*` directories. You should not do that for `AppData\Roaming\Microsoft\Crypto` – this is what is causing this error. It turns out, Win10’s `rsaenh.dll`, unlike Win7, is expecting to always find a couple of certain files there.

* * *

1Since Windows builder is not in [https://github.com/travis-ci/travis-cookbooks/](https://github.com/travis-ci/travis-cookbooks/), I cannot say for sure – or offer a patch
