GithubHelp home page GithubHelp logo

go-piv / go-ykpiv Goto Github PK

View Code? Open in Web Editor NEW
218.0 218.0 25.0 136 KB

Golang interface to manage Yubikeys, including a crypto.Signer & crypto.Decrypter interface

License: MIT License

Go 99.43% Dockerfile 0.57%
cryptography golang library ykpiv yubikey

go-ykpiv's People

Contributors

bluestealth avatar edwardbetts avatar ericchiang avatar immesys avatar jackofmosttrades avatar jtakkala avatar louisbrunner avatar luc-lynx avatar mgurevin avatar nbraud avatar paultag avatar ryandeivert avatar tianon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-ykpiv's Issues

ykls panics when a non-YubiKey smartcard reader is present

The following occurs if I run ykls while my laptop's ExpressCard smartcard reader is in:

$ dpkg -x /opt/deb/buildarea/golang-pault-go-ykpiv-dev_1.3.2-1_amd64.deb .
$ ./usr/bin/ykls --help
Reader:  Gemalto GemPC Express 00 00
panic: ykpiv ykpiv_connect: PKCS Error (-2) - Error in PCSC call

goroutine 1 [running]:
main.ohshit(...)
	pault.ag/go/ykpiv/cmd/ykls/ykls.go:31
main.main()
	pault.ag/go/ykpiv/cmd/ykls/ykls.go:44 +0x7cd

After removing the reader:

$ ./usr/bin/ykls 
Reader:  Yubico YubiKey FIDO+CCID 00 00
Version: 4.3.7
Serial:  6447364
Slot Authentication (9a): [email protected]

More flexible PIN entry

Hi @paultag, thanks a lot for this nice library!

In our current project, we sometimes use your package in an automated fashion and inject PIN/Management Key through the Options struct and that works perfectly.

However we also have a CLI/interactive tool where we prompt users for PIN entry. We only want to prompt when the PIN is required, so we can't set all the PIN, PUK, Management Key at start up. In such case it's a bit more difficult to integrate, we currently Close and New the card every-time so we can pass new options with new PINs, messy.

I am fine implementing a way to allow to request PIN entry more dynamically, but I'd like your opinion first on how this should look like.

I see several options:

  • Take an interface as argument in New so we can replace GetPIN, GetPUK, etc and do all our PIN entry logic there, most people could still use the normal Options as before so it is fully backward compatible
  • Ability to pass a *Options to New so we can change PIN, PUK, etc without having to recreate the whole key (not backward compatible and still fairly messy as we have to guess when you need the PIN, etc)
  • Some other options I have missed?

Looking forward to your feedback!

How to use

i have YubiKey NEO, and I'm trying to make software authorization with this yubikey (if verified yubikey is plugged, there is some conditional from go-ykpiv)

and i have no idea where to start, i have no idea how to verify if yubico is plugged, and so on.

Cross-compile error for Windows

I'm trying to build executable for Win10 platform, and get errors like:

► iMac@ykpiv$ GOOS=windows GOARCH=amd64 go build -o ykls.exe ykls.go
# pault.ag/go/ykpiv
src/pault.ag/go/ykpiv/tls.go:29:12: undefined: Slot

Everything is ok when building for darwin:

► iMac@ykpiv$ GOOS=darwin GOARCH=amd64 go build -o ykls.osx  ykls.go

and it works like charm (standalone). Same when running go run ......

But my main target is Windows-platform, and cross-compiling for windows (within osx) is best for developing my project. So I need some newbie help !

Maybe I'm missing something :

  • header files (#include <ykpiv.h>) ??
  • dll :s ?? I have osx libykcs11.dylib in my project root
  • some cgo flags ??

Can you help to figure my toolchain for this cross-compile.
Otherwise cross-compiling (osx -> win) is working very well (at least with std.libs).

But cgo or cross-compiling is new to me :(

Doing ECDH using Decrypt

The documentation is a little sparse on how to use slot.Decrypt to perform ECDH. I've got it "working" in that the correct value exists along the way, but the Decrypt function is failing because it is trying to run the output through pkcs1v15.Unpad. If I put a print in the Decrypt function that prints out the results of the C.GoBytes call, I can confirm it is generating the correct shared secret.

My program is something like this:

package main

import (
	"bytes"
	"crypto/ecdsa"
	"crypto/elliptic"
	"crypto/rand"
	"fmt"

	"github.com/aead/ecdh"
	"pault.ag/go/ykpiv"
)

func main() {
	pin := "123456"
	yubikey, err := ykpiv.New(ykpiv.Options{
		Reader: "Yubikey",
		PIN:    &pin,
	})
	yubikey.Login()
	//The private EC P-256 key has been generated in this slot before
	slt, _ := yubikey.Slot(ykpiv.KeyManagement)

	//Create the other side for testing
	p256 := ecdh.Generic(elliptic.P256())
	privateAlice, publicAlice, _ := p256.GenerateKey(rand.Reader)
	yubiPublic := slt.Public().(*ecdsa.PublicKey)
	yubiPublicAsPoint := ecdh.Point{X: yubiPublic.X, Y: yubiPublic.Y}

	//Get secret as computed by Alice
	expectedSecret := p256.ComputeSecret(privateAlice, yubiPublicAsPoint)

	//Convert Alice's public key into the format required by ykpiv
	pt := publicAlice.(ecdh.Point)
	alicePubkeyOctet := elliptic.Marshal(elliptic.P256(), pt.X, pt.Y)

	computedSecret, err := slt.Decrypt(rand.Reader, alicePubkeyOctet, nil)
	if err != nil {
		panic(err)
	}
	if bytes.Equal(expectedSecret, computedSecret) {
		fmt.Printf("the secrets matched!!!!\n")
	} else {
		fmt.Printf("failed to get the right ECDH answer\n")
	}
}

When I run it, I get the error "ykpiv: pkcs1v15: Input does not appear to be in PKCS#1 v 1.5 padded format" but as I say, the bytes returned by libykpiv are actually correct, just not in PKCS#1

Perhaps we need a function that looks like Decrypt but doesn't treat the result as PKCS#1 ?

SSL cert expired

It looks like the SSL certificate has expired for https://pault.ag.

This means a go get fails a la:

package pault.ag/go/ykpiv: unrecognized import path "pault.ag/go/ykpiv" (https fetch: Get https://pault.ag/go/ykpiv?go-get=1: x509: certificate has expired or is not yet valid)

Add a helper to initialize the token

Simple tool to set up a token:

  • Reset the applet if the PIN isn't known or stock
  • Set the PIN, PUK and Management Key (including derived management key)
  • Write back a self-signed Certificate or output a CSR for a given slot.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.