-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support to parse and load device MAC addresses from Device Mfg …
…Info Signed-off-by: Shrikant Temburwar <[email protected]>
- Loading branch information
1 parent
d757e21
commit 748ba6e
Showing
8 changed files
with
166 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
protocol/src/main/java/org/fidoalliance/fdo/protocol/api/MacAddress.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache 2.0 | ||
|
||
package org.fidoalliance.fdo.protocol.api; | ||
|
||
import java.security.cert.Certificate; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.fidoalliance.fdo.protocol.LoggerService; | ||
import org.fidoalliance.fdo.protocol.dispatch.ManufacturerKeySupplier; | ||
import org.fidoalliance.fdo.protocol.entity.ManufacturedVoucher; | ||
import org.fidoalliance.fdo.protocol.message.OwnershipVoucher; | ||
|
||
/** | ||
* Get API for Manufacturing voucher. | ||
*/ | ||
public class MacAddress extends RestApi { | ||
protected static final LoggerService logger = new LoggerService(MacAddress.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); | ||
} | ||
getResponse().getOutputStream().write(mfgVoucher.getMacAddresses()); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...ocol/src/main/java/org/fidoalliance/fdo/protocol/db/ManufacturingInfoStorageFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache 2.0 | ||
|
||
package org.fidoalliance.fdo.protocol.db; | ||
|
||
import java.io.IOException; | ||
import java.util.Date; | ||
import java.util.UUID; | ||
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; | ||
|
||
/** | ||
* Stores TPM EK Certificate into database. | ||
*/ | ||
public class ManufacturingInfoStorageFunction { | ||
|
||
/** | ||
* Stores TPM EK Certificate into database. | ||
* @param serialNo Device serial number that is used to retrieve TPM EK Data. | ||
* @param macAddresses MAC addresses received from the client. | ||
* @throws IOException Throws exception if required mfgVoucher is null. | ||
*/ | ||
public void store(String serialNo, byte[] macAddresses) 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.setMacAddresses(macAddresses); | ||
session.saveOrUpdate(mfgVoucher); | ||
trans.commit(); | ||
} catch (NotFoundException e) { | ||
throw new RuntimeException(e); | ||
} finally { | ||
session.close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.