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

Has2be sign certificate and certificate signed #13

Merged
merged 9 commits into from
Aug 29, 2023
21 changes: 21 additions & 0 deletions manager/handlers/has2be/certificate_signed_result.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: Apache-2.0

package has2be

import (
"context"

"github.com/thoughtworks/maeve-csms/manager/ocpp"
"github.com/thoughtworks/maeve-csms/manager/ocpp/has2be"
"golang.org/x/exp/slog"
)

type CertificateSignedResultHandler struct{}

func (c CertificateSignedResultHandler) HandleCallResult(ctx context.Context, chargeStationId string, request ocpp.Request, response ocpp.Response, state any) error {
resp := response.(*has2be.CertificateSignedResponseJson)

slog.Info("certificate signed response", slog.Any("status", resp.Status))
subnova marked this conversation as resolved.
Show resolved Hide resolved

return nil
}
40 changes: 40 additions & 0 deletions manager/handlers/has2be/sign_certificate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: Apache-2.0

package has2be

import (
"context"
handlers201 "github.com/thoughtworks/maeve-csms/manager/handlers/ocpp201"
"github.com/thoughtworks/maeve-csms/manager/ocpp"
typesHasToBe "github.com/thoughtworks/maeve-csms/manager/ocpp/has2be"
types201 "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201"
)

type SignCertificateHandler struct {
Handler201 handlers201.SignCertificateHandler
}

func (s SignCertificateHandler) HandleCall(ctx context.Context, chargeStationId string, request ocpp.Request) (ocpp.Response, error) {
req := request.(*typesHasToBe.SignCertificateRequestJson)
subnova marked this conversation as resolved.
Show resolved Hide resolved

req201 := &types201.SignCertificateRequestJson{
Csr: req.Csr,
}

if req.TypeOfCertificate != nil {
req201 = &types201.SignCertificateRequestJson{
Csr: req.Csr,
CertificateType: (*types201.CertificateSigningUseEnumType)(req.TypeOfCertificate),
}
}

res, err := s.Handler201.HandleCall(ctx, chargeStationId, req201)
if err != nil {
return nil, err
}
res201 := res.(*types201.SignCertificateResponseJson)

return &typesHasToBe.SignCertificateResponseJson{
Status: typesHasToBe.GenericStatusEnumType(res201.Status),
}, nil
}
3 changes: 3 additions & 0 deletions manager/handlers/has2be/sign_certificate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// SPDX-License-Identifier: Apache-2.0

package has2be_test
20 changes: 20 additions & 0 deletions manager/mqtt/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,17 @@ func NewV16Router(emitter Emitter,
},
},
},
"SignCertificate": {
NewRequest: func() ocpp.Request { return new(has2be.SignCertificateRequestJson) },
RequestSchema: "has2be/SignCertificateRequestJson.json",
ResponseSchema: "has2be/SignCertificateRequestJson.json",
Handler: handlersHasToBe.SignCertificateHandler{
Handler201: handlers201.SignCertificateHandler{
ChargeStationCertificateProvider: chargeStationCertProvider,
CallMaker: dataTransferCallMaker,
},
},
},
},
},
},
Expand All @@ -210,6 +221,15 @@ func NewV16Router(emitter Emitter,
Handler: handlers201.CertificateSignedResultHandler{},
},
},
"iso15118": { // has2be extensions
"CertificateSigned": {
NewRequest: func() ocpp.Request { return new(has2be.CertificateSignedRequestJson) },
NewResponse: func() ocpp.Response { return new(has2be.CertificateSignedResponseJson) },
RequestSchema: "has2be/CertificateSignedRequest.json",
ResponseSchema: "has2be/CertificateSignedResponse.json",
Handler: handlersHasToBe.CertificateSignedResultHandler{},
},
},
},
},
},
Expand Down
13 changes: 13 additions & 0 deletions manager/ocpp/has2be/certificate_signed_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package has2be
subnova marked this conversation as resolved.
Show resolved Hide resolved

type CertificateSignedRequestJson struct {
// The signed X.509 certificate, first DER encoded into binary, and then hex
// encoded into a case insensitive string. This can also contain the necessary sub
// CA certificates. In that case, the order should follow the certificate chain,
// starting from the leaf certificate.

// TypeOfCertificate corresponds to the JSON schema field "typeOfCertificate".
TypeOfCertificate CertificateSigningUseEnumType `json:"typeOfCertificate" yaml:"typeOfCertificate" mapstructure:"typeOfCertificate"`
}

func (*CertificateSignedRequestJson) IsRequest() {}
13 changes: 13 additions & 0 deletions manager/ocpp/has2be/certificate_signed_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package has2be
neinkeinkaffee marked this conversation as resolved.
Show resolved Hide resolved

type CertificateSignedStatusEnumType string

type CertificateSignedResponseJson struct {
// Status corresponds to the JSON schema field "status".
Status CertificateSignedStatusEnumType `json:"status" yaml:"status" mapstructure:"status"`
}

const CertificateSignedStatusEnumTypeAccepted CertificateSignedStatusEnumType = "Accepted"
const CertificateSignedStatusEnumTypeRejected CertificateSignedStatusEnumType = "Rejected"

func (*CertificateSignedResponseJson) IsResponse() {}
12 changes: 12 additions & 0 deletions manager/ocpp/has2be/sign_certificate_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package has2be
neinkeinkaffee marked this conversation as resolved.
Show resolved Hide resolved

type SignCertificateRequestJson struct {
// The Charging Station SHALL send the public key in form of a Certificate Signing
// Request (CSR) as described in the X.509 standard.
Csr string `json:"csr" yaml:"csr" mapstructure:"csr"`

// TypeOfCertificate corresponds to the JSON schema field "typeOfCertificate".
TypeOfCertificate *CertificateSigningUseEnumType `json:"typeOfCertificate,omitempty" yaml:"typeOfCertificate,omitempty" mapstructure:"typeOfCertificate,omitempty"`
}

func (*SignCertificateRequestJson) IsRequest() {}
13 changes: 13 additions & 0 deletions manager/ocpp/has2be/sign_certificate_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package has2be
neinkeinkaffee marked this conversation as resolved.
Show resolved Hide resolved

type GenericStatusEnumType string

const GenericStatusEnumTypeAccepted GenericStatusEnumType = "Accepted"
const GenericStatusEnumTypeRejected GenericStatusEnumType = "Rejected"

type SignCertificateResponseJson struct {
// Status corresponds to the JSON schema field "status".
Status GenericStatusEnumType `json:"status" yaml:"status" mapstructure:"status"`
}

func (*SignCertificateResponseJson) IsResponse() {}
5 changes: 5 additions & 0 deletions manager/ocpp/has2be/types.go
neinkeinkaffee marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ const HashAlgorithmEnumTypeSHA256 HashAlgorithmEnumType = "SHA256"
const HashAlgorithmEnumTypeSHA384 HashAlgorithmEnumType = "SHA384"
const HashAlgorithmEnumTypeSHA512 HashAlgorithmEnumType = "SHA512"

type CertificateSigningUseEnumType string

const CertificateSigningUseEnumTypeChargingStationCertificate CertificateSigningUseEnumType = "ChargingStationCertificate"
const CertificateSigningUseEnumTypeV2GCertificate CertificateSigningUseEnumType = "V2GCertificate"

type OCSPRequestDataType struct {
// HashAlgorithm corresponds to the JSON schema field "hashAlgorithm".
HashAlgorithm HashAlgorithmEnumType `json:"hashAlgorithm" yaml:"hashAlgorithm" mapstructure:"hashAlgorithm"`
Expand Down