github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/cmd/serve/credentials.go (about) 1 /* 2 * Copyright (c) 2018-2020 vChain, Inc. All Rights Reserved. 3 * This software is released under GPL3. 4 * The full license information can be found under: 5 * https://www.gnu.org/licenses/gpl-3.0.en.html 6 * 7 */ 8 9 package serve 10 11 import ( 12 "github.com/vchain-us/vcn/pkg/signature" 13 "net/http" 14 15 "github.com/vchain-us/vcn/pkg/api" 16 ) 17 18 func getCredential(r *http.Request) (user *api.User, passphrase string, err error) { 19 if email, password, ok := r.BasicAuth(); ok { 20 user = api.NewUser(email) 21 // we don't support otp from serve 22 err = user.Authenticate(password, "") 23 if err == nil { 24 if empty := r.Header.Get("x-notarization-password-empty"); empty == "" { 25 passphrase = r.Header.Get("x-notarization-password") 26 if passphrase == "" { 27 passphrase = password 28 } 29 } 30 // else use empty passphrase 31 } 32 } 33 return 34 } 35 36 func getLcUser(r *http.Request, lcHost, lcPort, lcCert string, skipTlsVerify, noTls bool) (*api.LcUser, error) { 37 apikey := r.Header.Get("x-notarization-lc-api-key") 38 ledger := r.Header.Get("x-notarization-lc-ledger") 39 publicKeyString := r.Header.Get("x-notarization-public-key") 40 publicKey, err := signature.GetECDSAPublicKeyFromBytes(signature.PreparePublicKey(publicKeyString)) 41 if err != nil { 42 return nil, err 43 } 44 return api.NewLcUser(apikey, ledger, lcHost, lcPort, lcCert, skipTlsVerify, noTls, publicKey) 45 }