Giter VIP home page Giter VIP logo

applepay's Introduction

ProcessOut Go

GoDoc

Installation

go get gopkg.in/processout.v4

Versioning

Versioning is done using gopkg.in, available at gopkg.in/processout.v4.

applepay's People

Contributors

andrea-vasapollo-cko avatar krystian-ogierman-cko avatar louis-paul avatar mateusz-walesiak-cko avatar pierre-lafanechaire-cko 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

applepay's Issues

"intermediate cert is not trusted by root" when cert issued by a CA other than AppleRootCA-G3

Hello,

Apple issued us a certificate from the AppleRootCA-G2. I am able to overwrite this CA file contents using the following:

AppleRootCertificatePath = "AppleRootCA-G3.crt"

but because there is no way to override the following OIDs:

leafCertificateOID = mustParseASN1ObjectIdentifier("1.2.840.113635.100.6.29")
interCertificateOID = mustParseASN1ObjectIdentifier("1.2.840.113635.100.6.2.14")

I receive the following error:

return errors.Wrap(err, "intermediate cert is not trusted by root")

Bug in ECDHE Implementation

I understand that this library is now deprecated, but perhaps this information will be useful for those who intend to fork this library.

Background

We run an internal fork of this library and noticed around a small percentage of applepay token decryptions were failing with a cipher: message authentication failed error in production. We tried to replicate the issue locally and managed to narrow it down to the ECDHE and KDF functions.

Issue

The combined use of the ecdheSharedSecret and deriveEncryptionKey functions do not correctly implement P256 ECDHE correctly. Notably, they fail to pad the X coordinate of the point to 32 bytes as specified in SEC 1, Version 2.0, Section 2.3.5.

Replication

This snippet (playground link) illustrates the difference between the ScalarMult and Bytes implementation with the correct crypto/ecdh implementation:

package main

import (
	"crypto/ecdh"
	"crypto/ecdsa"
	"crypto/elliptic"
	"fmt"
	"math/big"
)

func main() {
	k1 := []byte{42, 154, 0, 223, 84, 8, 55, 162, 117, 24, 142, 136, 128, 33, 143, 69, 194, 175, 251, 116, 183, 49, 190, 0, 228, 232, 21, 229, 203, 187, 226, 96}
	k2 := []byte{195, 5, 124, 117, 229, 83, 2, 62, 251, 203, 46, 195, 218, 215, 152, 7, 226, 64, 180, 63, 19, 183, 198, 37, 234, 194, 188, 222, 158, 85, 230, 191}

	privECDH, _ := ecdh.P256().NewPrivateKey(k1)
	privECDH2, _ := ecdh.P256().NewPrivateKey(k2)
	secretECDHE, _ := privECDH.ECDH(privECDH2.PublicKey())

	privECDSA := ecdhToECDSAPrivKey(privECDH)
	pubECDSA := ecdhToECDSAPublicKey(privECDH2.PublicKey())
	x, _ := privECDSA.Curve.ScalarMult(pubECDSA.X, pubECDSA.Y, privECDSA.D.Bytes())
	secretScalarMult := x.Bytes()
	secretMultFillBytes := make([]byte, 32)
	secretMultFillBytes = x.FillBytes(secretMultFillBytes)

	fmt.Printf("len:%d %x\n", len(secretECDHE), secretECDHE)                 // len:32 005363f5f75762476c04d7f32385629501368593df7e89aea4cdaebe4ae6c217
	fmt.Printf("len:%d %x\n", len(secretScalarMult), secretScalarMult)       // len:31 5363f5f75762476c04d7f32385629501368593df7e89aea4cdaebe4ae6c217
	fmt.Printf("len:%d %x\n", len(secretMultFillBytes), secretMultFillBytes) // len:32 005363f5f75762476c04d7f32385629501368593df7e89aea4cdaebe4ae6c217
}

func ecdhToECDSAPrivKey(key *ecdh.PrivateKey) *ecdsa.PrivateKey {
	return &ecdsa.PrivateKey{
		PublicKey: *ecdhToECDSAPublicKey(key.PublicKey()),
		D:         big.NewInt(0).SetBytes(key.Bytes()),
	}
}

func ecdhToECDSAPublicKey(key *ecdh.PublicKey) *ecdsa.PublicKey {
	rawKey := key.Bytes()
	return &ecdsa.PublicKey{
		Curve: elliptic.P256(),
		X:     big.NewInt(0).SetBytes(rawKey[1:33]),
		Y:     big.NewInt(0).SetBytes(rawKey[33:]),
	}
}

Fix

If you are using go1.20 or newer, I would recommend that you refactor the code to use crypto/ecdh instead. As at go1.20, (elliptic.Curve).ScalarMult contained a note advising against its use while recommending the then newly added crypto/ecdh package which correctly implements ECDHE. From go1.21 onwards, (elliptic.Curve).ScalarMult is marked as deprecated.

For versions less than go1.20, replacing the (*big.Int).Bytes() call in deriveEncryptionKey with (*big.Int).SetBytes on a 32 length byte slice would be an alternative.

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.