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

unexpected value for field Ipatokenotpkey returned by OtptokenAdd #9

Open
LukaszMoskala opened this issue Jan 26, 2023 · 2 comments
Open

Comments

@LukaszMoskala
Copy link

Hi,

ipa --version returns: VERSION: 4.10.0, API_VERSION: 2.249

Using OtptokenAdd returns the following error:

unexpected value for field Ipatokenotpkey: [map[__base64__:/FeLK5glrwwDEqpWGS1/R2pWRVmqk5pSp8M1jc0fJIw=]] ([]interface {})

The response is <nil>. However, the token is created in freeipa successfully, so I assume that this is problem with parsing of response.

Could generating the library again help? And which version of freeipa is this library currently based on?

Thanks

@riton
Copy link
Member

riton commented Jan 26, 2023

Hi @LukaszMoskala

Can you provide a minimal code sample to reproduce the error ?

Could generating the library again help ?

I don't think so. I think that this is due to a bad data type in the generated code.

And which version of freeipa is this library currently based on?

v4.6.8 was used to generate this library.

@LukaszMoskala
Copy link
Author

LukaszMoskala commented Jan 26, 2023

This is exactly the code that I'm using (with password redacted)

package main

import (
	"crypto/rand"
	"crypto/tls"
	"encoding/base32"
	"encoding/base64"
	"encoding/hex"
	"log"
	"net/http"

	"github.com/ccin2p3/go-freeipa/freeipa"
	"github.com/google/uuid"
)

func main() {

	tspt := &http.Transport{
		TLSClientConfig: &tls.Config{
			MinVersion: tls.VersionTLS12,
		},
	}

	c, err := freeipa.Connect("HOST", tspt, "admin", "PASSWORD")
	if err != nil {
		log.Fatal(err)
	}
	tokenuuid := uuid.NewString()
	tokenbytes := make([]byte, 32)
	rand.Read(tokenbytes)

	log.Printf("Token UUID: %s", tokenuuid)
	log.Printf("Token base32: %s", base32.StdEncoding.EncodeToString(tokenbytes))
	log.Printf("Token base64: %s", base64.StdEncoding.EncodeToString(tokenbytes))
	log.Printf("Token hex: %s", hex.EncodeToString(tokenbytes))

	addres, err := c.OtptokenAdd(tokenuuid, &freeipa.OtptokenAddArgs{}, &freeipa.OtptokenAddOptionalArgs{
		Type:                 freeipa.String("totp"),
		Ipatokenowner:        freeipa.String("test"),
		Ipatokenotpkey:       freeipa.String(base32.StdEncoding.EncodeToString(tokenbytes)),
		Ipatokenotpalgorithm: freeipa.String("sha1"),
		Ipatokenotpdigits:    freeipa.Int(6),
		All:                  freeipa.Bool(true),
		NoQrcode:             freeipa.Bool(true),
	})
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Response: %+v", addres)
}

If I remove error checking at the end, the response is <nil>

Thank you for your time

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

No branches or pull requests

2 participants