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

SDK-2259:added retrieve qr code #290

Merged
merged 57 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
6691dec
SDK-2259:added retrieve qr code
mehmet-yoti Oct 22, 2023
be2b96b
SDK-2235 added retrieve receipt
mehmet-yoti Oct 23, 2023
6f50c88
SDK-2235 Added Retrieve Receipt
mehmet-yoti Oct 25, 2023
fb79e33
SDK-2235 Added Retrieve Receipt
mehmet-yoti Oct 25, 2023
1586dea
SDK-2235 Added Retrieve Receipt
mehmet-yoti Oct 25, 2023
c2d3b6c
SDK-2235 Added Retrieve Receipt
mehmet-yoti Oct 25, 2023
22d0896
SDK-2254 Resolved pr comments
mehmet-yoti Nov 1, 2023
359a293
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
cb5f083
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
ce57837
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
f61e496
SDK-2254 Resolved pr comments
mehmet-yoti Nov 1, 2023
708fe86
SDK-2254:updated pr changes
mehmet-yoti Nov 2, 2023
2a0f087
SDK-2254 removed unused builder
mehmet-yoti Nov 5, 2023
5912800
SDK-2259:added retrieve qr code
mehmet-yoti Oct 22, 2023
e4a1fc8
SDK-2254 Removed unused examples and updated function namings
mehmet-yoti Nov 1, 2023
06d91c3
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
f410402
SDK-2259:removed unused example files
mehmet-yoti Nov 1, 2023
fd1f342
Merge remote-tracking branch 'origin/SDK-2259-go-retrieve-qr-code' in…
Nov 7, 2023
86d40a4
SDK-2259:added retrieve qr code structs
mehmet-yoti Oct 22, 2023
60e2f4d
SDK-2254 Removed unused examples and updated function namings
mehmet-yoti Nov 1, 2023
7a955f4
SDK-2259:removed unused example files
mehmet-yoti Nov 1, 2023
33131cc
Merge remote-tracking branch 'origin/SDK-2259-go-retrieve-qr-code' in…
Nov 7, 2023
ae46a53
SDK-2254 Resolved pr comments
mehmet-yoti Nov 1, 2023
22bbe7d
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
9a619e8
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
bc20038
SDK-2259:updated needed pr reviews
mehmet-yoti Nov 1, 2023
00ef7b0
SDK-2254 Resolved pr comments
mehmet-yoti Nov 1, 2023
4cf2791
SDK-2254:updated pr changes
mehmet-yoti Nov 2, 2023
ad1f3f9
SDK-2254 removed unused builder
mehmet-yoti Nov 5, 2023
87d61de
SDK-2259:added retrieve qr code structs
mehmet-yoti Oct 22, 2023
6c2d312
SDK-2254 Removed unused examples and updated function namings
mehmet-yoti Nov 1, 2023
d40c218
SDK-2259:removed unused example files
mehmet-yoti Nov 1, 2023
f8657c2
SDK-2254 Removed unused examples and updated function namings
mehmet-yoti Nov 1, 2023
4c019b3
SDK-2259:removed unused example files
mehmet-yoti Nov 1, 2023
a841a3e
SDK-2235:error handling, updated comments
mehmet-yoti Nov 7, 2023
87f5098
SDK-2235:updated method descriptions and addedd error handlers with d…
mehmet-yoti Nov 8, 2023
2492915
SDK-2235:added some error handling, updated comments, added error han…
mehmet-yoti Nov 10, 2023
5bf052f
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
9661755
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
75502ef
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
b7d7b23
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
8e20b5e
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
b893957
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
4993e35
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
e52a26c
Update cryptoutil/crypto_utils.go
mehmet-yoti Nov 23, 2023
b9d8fed
Update digitalidentity/service.go
mehmet-yoti Nov 23, 2023
c09c2c2
Update cryptoutil/crypto_utils.go
mehmet-yoti Nov 23, 2023
8dd3c7c
SDK-2235: added error details, cleaned unneccessary func and merged i…
mehmet-yoti Nov 24, 2023
f705d44
Merge branch 'SDK-2259-go-retrieve-qr-code' into SDK-2235-share-v-2-r…
mehmet-yoti Nov 24, 2023
a4775d2
Update cryptoutil/crypto_utils.go
mehmet-yoti Dec 7, 2023
3da5372
SDK-2235:reduced complexity
mehmet-yoti Dec 7, 2023
9d403b8
SDK-2235 removed unused method, added panic controls, added error con…
mehmet-yoti Dec 12, 2023
af99524
SDK-2235 added error contexts
mehmet-yoti Dec 12, 2023
a3d8314
Update digitalidentity/service.go
mehmet-yoti Dec 14, 2023
5f1ec57
Update digitalidentity/service.go
mehmet-yoti Dec 14, 2023
3fb2de7
SDK-2235 updated error context text
mehmet-yoti Dec 14, 2023
ac64677
Merge pull request #289 from getyoti/SDK-2235-share-v-2-retrieve-receipt
mehmet-yoti Dec 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ report.json
# idea files
.idea

# Generated binaries
/_examples/docscan/docscan

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=getyoti%3Ago&metric=code_smells)](https://sonarcloud.io/dashboard?id=getyoti%3Ago)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=getyoti%3Ago&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=getyoti%3Ago)

Welcome to the Yoti Go SDK. This repo contains the tools and step by step instructions you need to quickly integrate your Go back-end with Yoti so that your users can share their identity details with your application in a secure and trusted way.
Welcome to the Yoti Go SDK. This repo contains the tools and step by step instructions you need to quickly integrate your Go back-end with Yoti so that your users can receipt their identity details with your application in a secure and trusted way.

## Table of Contents

Expand Down
8 changes: 8 additions & 0 deletions _examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
.env
# Generated binaries
docscan/docscan
idv/idv
aml/aml
docscansandbox/docscansandbox
profile/profile
profilesandbox/profilesandbox
digitalidentity/digitalidentity
2 changes: 2 additions & 0 deletions _examples/digitalidentity/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YOTI_CLIENT_SDK_ID=
YOTI_KEY_FILE_PATH=
8 changes: 8 additions & 0 deletions _examples/digitalidentity/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/images/YotiSelfie.jpeg

# Example project generated self-signed certificate
/yotiSelfSignedCert.pem
/yotiSelfSignedKey.pem

# Compiled binary
/digitalidentity
46 changes: 46 additions & 0 deletions _examples/digitalidentity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Table of Contents

1) [Setup](#setup) -
How to initialise the Yoti client

1) [Running the digitalidentity examples](#running-the-profile-example) -
Running the digitalidentity example

## Setup

The YotiClient is the SDK entry point. To initialise it you need include the following snippet inside your endpoint initialisation section:

```Go
clientSdkID := "your-client-sdk-id"
key, err := os.ReadFile("path/to/your-application-pem-file.pem")
if err != nil {
// handle key load error
}

client, err := yoti.NewClient(
clientSdkID,
key)
```

Where:

* `"your-client-sdk-id"` is the SDK Client Identifier generated by Yoti Hub in the Key tab when you create your application.

* `path/to/your-application-pem-file.pem` is the path to the application pem file. It can be downloaded from the Keys tab in the [Yoti Hub](https://hub.yoti.com/).

Please do not open the pem file as this might corrupt the key, and you will need regenerate your key.

Keeping your settings and access keys outside your repository is highly recommended. You can use a package like [godotenv](https://github.com/joho/godotenv) to manage environment variables more easily.


## Running the DigitalIdentity Example

1. Change directory to the profile example folder: `cd _examples/digitalidentity`
2. On the [Yoti Hub](https://hub.yoti.com/):
1. Set the application domain of your app to `localhost:8080`
2. Set the scenario callback URL to `/digitalidentity`
3. Rename the [.env.example](_examples/digitalidentity/.env.example) file to `.env` and fill in the required configuration values (mentioned in the [Configuration](#configuration) section)
4. Build with `go build`
5. Start the compiled program by running `./digitalidentity`

Visiting `https://localhost:8080/` should show a webpage with a Yoti button rendered on it
175 changes: 175 additions & 0 deletions _examples/digitalidentity/certificatehelper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package main

import (
"crypto/ecdsa"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"log"
"math/big"
"net"
"os"
"strings"
"time"
)

var (
validFrom = ""
validFor = 2 * 365 * 24 * time.Hour
isCA = true
rsaBits = 2048
)

func publicKey(priv interface{}) interface{} {
switch k := priv.(type) {
case *rsa.PrivateKey:
return &k.PublicKey
case *ecdsa.PrivateKey:
return &k.PublicKey
default:
return nil
}
}

func pemBlockForKey(priv interface{}) *pem.Block {
switch k := priv.(type) {
case *rsa.PrivateKey:
return &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(k)}
case *ecdsa.PrivateKey:
b, err := x509.MarshalECPrivateKey(k)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to marshal ECDSA private key: %v", err)
os.Exit(2)
}
return &pem.Block{Type: "EC PRIVATE KEY", Bytes: b}
default:
return nil
}
}

func certificatePresenceCheck(certPath string, keyPath string) (present bool) {
if _, err := os.Stat(certPath); os.IsNotExist(err) {
return false
}
if _, err := os.Stat(keyPath); os.IsNotExist(err) {
return false
}
return true
}

func generateSelfSignedCertificate(certPath, keyPath, host string) error {
priv, err := rsa.GenerateKey(rand.Reader, rsaBits)
if err != nil {
log.Printf("failed to generate private key: %s", err)
return err
}

notBefore, err := parseNotBefore(validFrom)
if err != nil {
log.Printf("failed to parse 'Not Before' value of cert using validFrom %q, error was: %s", validFrom, err)
return err
}

notAfter := notBefore.Add(validFor)

serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
if err != nil {
log.Printf("failed to generate serial number: %s", err)
return err
}

template := x509.Certificate{
SerialNumber: serialNumber,
Subject: pkix.Name{
Organization: []string{"Yoti"},
},
NotBefore: notBefore,
NotAfter: notAfter,

KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
}

hosts := strings.Split(host, ",")
for _, h := range hosts {
if ip := net.ParseIP(h); ip != nil {
template.IPAddresses = append(template.IPAddresses, ip)
} else {
template.DNSNames = append(template.DNSNames, h)
}
}

if isCA {
template.IsCA = true
template.KeyUsage |= x509.KeyUsageCertSign
}

derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, publicKey(priv), priv)
if err != nil {
log.Printf("Failed to create certificate: %s", err)
return err
}

err = createPemFile(certPath, derBytes)
if err != nil {
log.Printf("failed to create pem file at %q: %s", certPath, err)
return err
}
log.Printf("written %s\n", certPath)

err = createKeyFile(keyPath, priv)
if err != nil {
log.Printf("failed to create key file at %q: %s", keyPath, err)
return err
}
log.Printf("written %s\n", keyPath)

return nil
}

func createPemFile(certPath string, derBytes []byte) error {
certOut, err := os.Create(certPath)

if err != nil {
log.Printf("failed to open "+certPath+" for writing: %s", err)
return err
}

defer certOut.Close()
err = pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})

return err
}

func createKeyFile(keyPath string, privateKey interface{}) error {
keyOut, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)

if err != nil {
log.Print("failed to open "+keyPath+" for writing:", err)
return err
}

defer keyOut.Close()
err = pem.Encode(keyOut, pemBlockForKey(privateKey))

return err
}

func parseNotBefore(validFrom string) (notBefore time.Time, err error) {
if len(validFrom) == 0 {
notBefore = time.Now()
} else {
notBefore, err = time.Parse("Jan 2 15:04:05 2006", validFrom)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to parse creation date: %s\n", err)
return time.Time{}, err
}
}

return notBefore, nil
}
24 changes: 24 additions & 0 deletions _examples/digitalidentity/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"html/template"
"log"
"net/http"
)

func errorPage(w http.ResponseWriter, r *http.Request) {
templateVars := map[string]interface{}{
"yotiError": r.Context().Value(contextKey("yotiError")).(string),
}
log.Printf("%s", templateVars["yotiError"])
t, err := template.ParseFiles("error.html")
if err != nil {
panic(errParsingTheTemplate + err.Error())
}

err = t.Execute(w, templateVars)
if err != nil {
panic(errApplyingTheParsedTemplate + err.Error())
}

}
11 changes: 11 additions & 0 deletions _examples/digitalidentity/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Yoti Example Project - Error</title>
</head>
<body style="text-align: center; margin: 200px 0">
<h1>An Error Occurred</h1>
<p><b>Error: </b>{{.yotiError}}</p>
</body>
</html>
12 changes: 12 additions & 0 deletions _examples/digitalidentity/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module digitalidentity

go 1.19

require (
github.com/getyoti/yoti-go-sdk/v3 v3.0.0
github.com/joho/godotenv v1.3.0
)

require google.golang.org/protobuf v1.30.0 // indirect

replace github.com/getyoti/yoti-go-sdk/v3 => ../../
11 changes: 11 additions & 0 deletions _examples/digitalidentity/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gotest.tools/v3 v3.3.0 h1:MfDY1b1/0xN1CyMlQDac0ziEy9zJQd9CXBRRDHw2jJo=
Loading
Loading