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

Accept Endorsement Key as part of DI app start #686

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions component-samples/demo/aio/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@
<url-pattern>/api/v1/mfg/vouchers/*</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>MfgVoucher</servlet-name>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<servlet-name>MfgVoucher</servlet-name>
<servlet-name>EkVoucher</servlet-name>

<servlet-class>org.fidoalliance.fdo.protocol.api.RestApiServlet</servlet-class>
<init-param>
<param-name>Api-Class</param-name>
<param-value>org.fidoalliance.fdo.protocol.api.EkVoucher</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>EkVoucher</servlet-name>
<url-pattern>/api/v1/mfg/ekcert/*</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>CertificateApi</servlet-name>
<servlet-class>org.fidoalliance.fdo.protocol.api.RestApiServlet</servlet-class>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Optional;
import org.apache.commons.codec.binary.Hex;
import org.fidoalliance.fdo.protocol.db.FdoSysModuleExtra;
import org.fidoalliance.fdo.protocol.db.ManufacturingInfoStorageFunction;
import org.fidoalliance.fdo.protocol.db.OnboardConfigSupplier;
import org.fidoalliance.fdo.protocol.dispatch.CertSignatureFunction;
import org.fidoalliance.fdo.protocol.dispatch.CredReuseFunction;
Expand Down Expand Up @@ -373,6 +374,7 @@ protected void doAppStart(DispatchMessage request, DispatchMessage response) thr

ManufacturingInfo mfgInfo = Mapper.INSTANCE.readValue(appStart.getManufacturingInfo(),
ManufacturingInfo.class);

SimpleStorage storage = createVoucher(mfgInfo, request.getProtocolVersion());

SessionManager manager = getWorker(SessionManager.class);
Expand Down Expand Up @@ -435,6 +437,9 @@ protected void doSetHmac(DispatchMessage request, DispatchMessage response) thro
VoucherStorageFunction storageFunction = getWorker(VoucherStorageFunction.class);
storageFunction.apply(info.getSerialNumber(), voucher);

ManufacturingInfoStorageFunction infoStore = new ManufacturingInfoStorageFunction();
infoStore.store(info.getSerialNumber(), info.getEndorsementKey());

//save the voucher
response.setMessage(Mapper.INSTANCE.writeValue(new DiDone()));
manager.expireSession(request.getAuthToken().get());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2022 Intel Corporation
// SPDX-License-Identifier: Apache 2.0

package org.fidoalliance.fdo.protocol.api;

import org.fidoalliance.fdo.protocol.*;
import org.fidoalliance.fdo.protocol.dispatch.ManufacturerKeySupplier;
import org.fidoalliance.fdo.protocol.entity.ManufacturedVoucher;
import org.fidoalliance.fdo.protocol.message.OwnershipVoucher;

import java.security.cert.Certificate;
import java.util.Arrays;
import java.util.List;

/**
* Get API for Manufacturing voucher.
*/
public class EkVoucher extends RestApi {
protected static final LoggerService logger = new LoggerService(EkVoucher.class);


@Override
public void doGet() throws Exception {

String path = getLastSegment();
logger.info("Manufacturing Voucher SerialNo: " + path);

ManufacturedVoucher mfgVoucher = getSession().get(ManufacturedVoucher.class, path);
if (mfgVoucher == null) {
logger.warn("Mfg voucher is null");
throw new NotFoundException(path);
}
String text = Arrays.toString(mfgVoucher.getEkData());
getResponse().setContentType(HttpUtils.HTTP_PLAIN_TEXT);
getResponse().getWriter().print(text);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2022 Intel Corporation
// SPDX-License-Identifier: Apache 2.0

package org.fidoalliance.fdo.protocol.db;

import org.fidoalliance.fdo.protocol.Mapper;
import org.fidoalliance.fdo.protocol.api.NotFoundException;
import org.fidoalliance.fdo.protocol.dispatch.VoucherStorageFunction;
import org.fidoalliance.fdo.protocol.entity.ManufacturedVoucher;
import org.fidoalliance.fdo.protocol.message.ManufacturingInfo;
import org.fidoalliance.fdo.protocol.message.OwnershipVoucher;
import org.fidoalliance.fdo.protocol.message.OwnershipVoucherHeader;
import org.hibernate.Session;
import org.hibernate.Transaction;

import java.io.IOException;
import java.util.Date;
import java.util.UUID;

public class ManufacturingInfoStorageFunction {


public void store(String serialNo, byte[] endorsementKey) throws IOException {
Session session = HibernateUtil.getSessionFactory().openSession();
try {
ManufacturedVoucher mfgVoucher = session.get(ManufacturedVoucher.class, serialNo);
if (mfgVoucher == null) {
throw new NotFoundException(serialNo);
}
Transaction trans = session.beginTransaction();
mfgVoucher.setEkData(endorsementKey);
session.saveOrUpdate(mfgVoucher);
trans.commit();
} catch (NotFoundException e) {
throw new RuntimeException(e);
} finally {
session.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public class ManufacturedVoucher {
@Temporal(TemporalType.TIMESTAMP)
private Date createdOn;

@Lob
@Column(name = "ekData", length = 65535, nullable = false)
private byte[] ekData;


public String getSerialNo() {
return serialNo;
}
Expand All @@ -41,6 +46,15 @@ public Date getCreatedOn() {
return createdOn;
}

public byte[] getEkData() {
return ekData;
}

public void setEkData(byte[] ekData) {
this.ekData = ekData;
}


public void setSerialNo(String id) {
this.serialNo = id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@JsonPropertyOrder(
{"keyType", "keyEnc", "serialNumber", "deviceInfo", "certInfo",
"onDieDeviceCertChain", "testSignature", "testSigMaroePrefix"}
"onDieDeviceCertChain", "endorsementKey", "testSignature", "testSigMaroePrefix"}
)
@JsonSerialize(using = ManufacturingInfoSerializer.class)
@JsonDeserialize(using = ManufacturingInfoDeserializer.class)
Expand All @@ -40,6 +40,9 @@ public class ManufacturingInfo {
@JsonProperty("onDieDeviceCertChain")
private byte[] onDieDeviceCertChain;

@JsonProperty("endorsementKey")
private byte[] endorsementKey;

@JsonProperty("testSignature")
private byte[] testSignature;

Expand Down Expand Up @@ -76,6 +79,11 @@ public byte[] getOnDieDeviceCertChain() {
return onDieDeviceCertChain;
}

@JsonIgnore
public byte[] getEndorsementKey() {
return endorsementKey;
}

@JsonIgnore
public byte[] getTestSignature() {
return testSignature;
Expand Down Expand Up @@ -116,6 +124,11 @@ public void setOnDieDeviceCertChain(byte[] onDieDeviceCertChain) {
this.onDieDeviceCertChain = onDieDeviceCertChain;
}

@JsonIgnore
public void setEndorsementKey(byte[] endorsementKey) {
this.endorsementKey = endorsementKey;
}

@JsonIgnore
public void setTestSignature(byte[] testSignature) {
this.testSignature = testSignature;
Expand Down
Loading