number571 / go-cryptopro

ГОСТ функции КриптоПро для языка Go.
MIT License
17 stars 11 forks source link

Getting an error when trying to sign message #2

Open gasparyanyur opened 1 year ago

gasparyanyur commented 1 year ago

On my ubuntu 20 machine I have already installed and configured CryptoPro. So now I am trying to sign message using number571/go-cryptopro but getting the following error:

E[-2146893792][CreateContainer: CryptGenKey]
panic: error code: -3

goroutine 1 [running]:
github.com/number571/go-cryptopro/gost_r_34_10_2012.GenPrivKey(0xc000048cb0, 0x4b99e0, 0xc0000ac401)
        /root/go/pkg/mod/github.com/number571/go-cryptopro@v1.0.3/gost_r_34_10_2012/gost.go:92 +0x25a
github.com/number571/go-cryptopro/gost_r_34_10_2012.init.0()
        /root/go/pkg/mod/github.com/number571/go-cryptopro@v1.0.3/gost_r_34_10_2012/gost.go:18 +0x69
exit status 2

Here is the code

cfg := gkeys.NewConfig(gkeys.K256, "mkk", "password")

    priv, err := gkeys.NewPrivKey(cfg)
    if err != nil {
        fmt.Println(err)
        return
    }

    msg := []byte("hello, world!")
    sign, err := priv.Sign(msg)
    if err != nil {
        fmt.Println(err)
        return
    }

        fmt.Println(msg)
gasparyanyur commented 1 year ago

@number571 plz help to solve this error

number571 commented 1 year ago

Hm... This problem from CryptGenKey(hProv, AT_SIGNATURE, CRYPT_EXPORTABLE, &hKey) C code line. You can find out the cause of the error in more detail using printf of the returned code in C and compare it with the Crypto Pro constants http://cpdn.cryptopro.ru/default.asp?url=content/csp_trunk/html/Titul.html. Maybe problem in CRYPT_EXPORTABLE param. I'll also try to see.

gasparyanyur commented 1 year ago

@number571 thank you very much.

@number571 what is the format for container name when trying to make a new config instance? jsut mkk or \HDIMAGE\mkk?

Also just noticed the error caused when trying to import package. Maybe any init function has been called and the error has been catched.

gasparyanyur commented 1 year ago

@number571 just noticed that go test also doesnt pass. package github.com/number571/go-cryptopro@v1.0.3/gost_r_34_10_2012 go test -v -bench=. -benchtime=100x