win-ca icon indicating copy to clipboard operation
win-ca copied to clipboard

Unreadable codes in Chinese when use win-ca

Open yaphone opened this issue 4 years ago • 6 comments

Hi, I use win-ca in my nodejs project to get certificate, and here is my code:

export function getAllCerts() {
  return new Promise(resolve => {
    ca({
      async: true,
      format: ca.der2.txt,
      ondata: roots,
      onend: resolve
    })
  }).then(() => {
    console.log(roots)
    return roots
  })

And it works well in English format, but when the certificate content contains Chinese, I got unreadable codes. I think the reason is the encoding format in win-ca,and I want to know how to resolve this problem.

THX very much!

yaphone avatar May 31 '20 05:05 yaphone

node -v 10.14.1 win-ca 3.2.0

yaphone avatar May 31 '20 06:05 yaphone

Well, certificates with UTF-8 strings is still terra incognita in Russia, we strongly prefer to avoid them, using transliteration to Latin-1. So, such errors are very likely to occur and voila!

I don't even know whose error is this - mine on node-forge`s. Or both ;-)

Could you please attach sample certificate that leads to unreadable text?

So far I believe you can fetch certificates in PEM format and parse them yourself. I'll try to fix but it will take some time...

ukoloff avatar Jun 01 '20 05:06 ukoloff

THX for your reply.

I will attach a root certificate whose contents contains Chinese when I back to my office tomrrow~

This is a great project, and very helpful to our project! I have tried to debug win-ca code, but I found it hard to understand,and I still trying...

yaphone avatar Jun 01 '20 16:06 yaphone

I found this may not the problem with coding format, I generated a certificate and store it in 'MY' by follow cmd: makecert -n "CN=陕西税务总局 测试Subject" -b 08/05/2019 -e 08/05/2022 -ss my -r TestIssuer.cer Succeeded then use it in my node project by win-ca, I got right result: image

And the unreadable coding certificate is in USB KEY, I can not get the hardware right now, I will try later~

yaphone avatar Jun 02 '20 07:06 yaphone

Hi, bro I think I get the point, it is a bug of node-forge, I have make a PR to node-forge repository, you can check it here

yaphone avatar Jun 09 '20 08:06 yaphone

I spent some time playing with UTF-8 certificates and that is what I think now:

  1. Your PR to node-forge should be cancelled. It changes API so it would break a lot of dependent packages
  2. Inside win-ca I manually convert binary strings to UTF-8
  3. It seems to fix problems with all UTF-8 certificates I have got (more than 20, including Chines, Turkish and Hungarian)
  4. I released beta-version of win-ca. Install as npm i win-ca@utf8
  5. Feel free to test and report

ukoloff avatar Sep 15 '20 15:09 ukoloff