0

How to use capicom to remove a certificate from usb token.
I wrote this code but It does not work I get error " can not find the smart card" in line MyStore.Open(CAPICOM_SMART_CARD_USER_STORE, "My", CAPICOM_STORE_OPEN_READ_WRITE);

 function DeleteCertificate(strUserCertigicateThumbprint) {
 try {

    if (strUserCertigicateThumbprint == null ||
        strUserCertigicateThumbprint == "")
        return null;
    var oUtils = new ActiveXObject("CAPICOM.Utilities");

    var MyStore = new ActiveXObject("CAPICOM.Store");
    MyStore.Open(CAPICOM_SMART_CARD_USER_STORE, "My", CAPICOM_STORE_OPEN_READ_WRITE);
    var FilteredCertificates = MyStore.Certificates.Find(CAPICOM_CERTIFICATE_FIND_SHA1_HASH, strUserCertigicateThumbprint);
    if (FilteredCertificates.Count == 0)
        return null;
    else {
        var cert = FilteredCertificates.Item(1);
        MyStore.Remove(cert);


    }
    MyStore = null;
    FilteredCertificates = null;
    return true;
}
catch (e) {
    MyStore = null;
    FilteredCertificates = null;
}
return false;}
Fatemeh
  • 177
  • 15
  • Does not work, but is any error raised? Try adding some `console.log` in there to check what id does, what it does not. Your code as is, would behave the same with not finding the certificate and when an error raises when trying to remove it – Cleptus Feb 22 '20 at 12:41
  • I figuer out I sould use MyStore.Remove(certobject); but this code will delete a certificate from my personal certificates in my system and does not delete from my usb token. I edited my code to work with usb token but I get new error – Fatemeh Feb 22 '20 at 13:14
  • The certificate is being deleted, from the place `capicom` has right to, the certificates store. In addition to that, you should try to get a way to delete the file using javascript, and that is totally a different question. The browser does **not** have read/write access to all the file system by default. – Cleptus Feb 22 '20 at 20:34
  • this code is a javascript code, I can delete a certificate from system personal certificate store. I search a lot but I haven't found any thing. I issue a new certificate in token and I want to delete old one for customer. Is a bad Idea? why does not every one have this question in net? – Fatemeh Feb 23 '20 at 03:48
  • Revocate the old certificate if you have not already done that. If it is revocated, the only reason to try to physically delete it is.. cleanup. You could remove the cert from the store because of ActiveX, not because of JavaScript features. JavaScript does no allo deleting random files, you would need to develop an ActiveX to achieve that – Cleptus Feb 24 '20 at 08:08

0 Answers0