Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ShangMi SM2 Public Key #981

Closed
osvalban opened this issue Sep 15, 2023 · 5 comments
Closed

Add support for ShangMi SM2 Public Key #981

osvalban opened this issue Sep 15, 2023 · 5 comments
Assignees

Comments

@osvalban
Copy link

Hello,

Abstract
https://github.com/emmansun/gmsm provides Golang implementations for Chinese crypto standards. In particular, it would be great to accept ShangMi SM2 Public Key (based on ecdsa) for generation of JWKs by this library.

Describe the proposed solution/change

package main

import (
	"crypto/rand"
	"fmt"

	"github.com/emmansun/gmsm/sm2"
	"github.com/lestrrat-go/jwx/jwk"
)

func main() {
	shangmi2pk, _ := sm2.GenerateKey(rand.Reader)
	_, err := jwk.New(shangmi2pk.Public())
	fmt.Println(err)
}

failed to initialize *jwk.ecdsaPublicKey from *ecdsa.PublicKey: invalid elliptic curve &{%!s(func() *sm2ec.SM2P256Point=0x4c9a80) %!s(*elliptic.CurveParams=&{0xc0000c8060 0xc0000c80a0 0xc0000c80e0 0xc0000c8120 0xc0000c8160 256 sm2p256v1})}

Analysis
ecutil.go mentions algorithms may be compiled in/out. If you could advise how to add on a compatible elliptic curve, that could also help.

Thank you.

@lestrrat
Copy link
Collaborator

That's actually something I'm trying to smooth out in #969 (related: #912)
You can actually register keys as it is, but EC keys are turning out to be a pain because of the conversion between strings and elliptic.Curve or similar (there's also the confusing reality of having to represent ed25519 curves in a sane manner). As of now I don't have a good answer. If you are curious, you could take a look at the internals and let me know if you have ideas.

I'm currently distracted by other things in life, so while I do intend to work on it, I can't give you a timeline if it's just me working on it.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2023

This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Oct 4, 2023
@lestrrat lestrrat removed the Stale label Oct 4, 2023
@lestrrat
Copy link
Collaborator

lestrrat commented Oct 4, 2023

Removing stale label. We'll probably allow this to happen when v3 comes out

@lestrrat
Copy link
Collaborator

lestrrat commented Nov 3, 2023

@osvalban I think this is now possible using the (as of yet unreleased) develop/v3 branch.

This branch contains an example. Please look at #1012 and see if it works for you

@lestrrat
Copy link
Collaborator

#1012 has been merged to v3, I haven't heard back, so closing this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants