Hi, The attached patch adds sedutil 1.49.13, a utility for inspecting and managing TCG Opal, Enterprise, Pyrite, and Ruby self-encrypting drives.
The port builds only sedutil-cli; the PBA components are intentionally omitted. Its OpenBSD backend uses ATAIOCCOMMAND and SCIOCCOMMAND and supports native ATA, SAS/SCSI, and SAT devices. NVMe discovery is included, although the kernel passthrough interface does not currently permit the Security Send/Receive commands needed for Opal management. It also carries a one-line upstream fix that makes -n -t correctly decode pre-hashed credentials (upstream has this issue reported since August). This fills a useful gap for managing hardware-encrypted disks directly from OpenBSD. It was tested on amd64 with a native SAS Enterprise SSC drive, including discovery, password changes, and locking-range lock and unlock operations. make package, update-plist, port-lib-depends-check, and portcheck -A pass. greets Dariusz Swiderski -- A mouse is a device used to point at the xterm you want to type in. Index: sysutils/sedutil/Makefile --- /dev/null +++ sysutils/sedutil/Makefile @@ -0,0 +1,25 @@ +# The upstream protocol parser assumes a little-endian host. +ONLY_FOR_ARCHS = amd64 arm64 armv7 i386 riscv64 + +COMMENT = manage TCG Opal self-encrypting drives + +DIST_TUPLE = github Drive-Trust-Alliance sedutil 1.49.13 . + +CATEGORIES = sysutils security + +HOMEPAGE = https://github.com/Drive-Trust-Alliance/sedutil + +# GPLv3+ +PERMIT_PACKAGE = Yes + +WANTLIB += c m ${COMPILER_LIBCXX} + +COMPILER = base-clang ports-gcc + +CONFIGURE_STYLE = autoreconf +AUTOCONF_VERSION = 2.71 +AUTOMAKE_VERSION = 1.16 + +DEBUG_PACKAGES = ${BUILD_PACKAGES} + +.include <bsd.port.mk> Index: sysutils/sedutil/distinfo --- /dev/null +++ sysutils/sedutil/distinfo @@ -0,0 +1,2 @@ +SHA256 (Drive-Trust-Alliance-sedutil-1.49.13.tar.gz) = MmgwZTMcfGGwc1Ww60Q8q880M/RhO2hVLkPEZtACTy0= +SIZE (Drive-Trust-Alliance-sedutil-1.49.13.tar.gz) = 43540280 Index: sysutils/sedutil/patches/patch-Common_DtaOpenBSD_cpp --- /dev/null +++ sysutils/sedutil/patches/patch-Common_DtaOpenBSD_cpp @@ -0,0 +1,509 @@ +Index: Common/DtaOpenBSD.cpp +--- Common/DtaOpenBSD.cpp.orig ++++ Common/DtaOpenBSD.cpp +@@ -0,0 +1,505 @@ ++/* ++ * OpenBSD storage passthrough backend for sedutil-cli. ++ * ++ * This file is part of sedutil and is distributed under the GNU General ++ * Public License, version 3 or (at your option) any later version. ++ */ ++ ++#include <sys/types.h> ++#include <sys/ataio.h> ++#include <sys/disklabel.h> ++#include <sys/dkio.h> ++#include <sys/ioctl.h> ++#include <sys/scsiio.h> ++#include <sys/stat.h> ++ ++#include <dev/biovar.h> ++#include <dev/ic/nvmeio.h> ++ ++#include <algorithm> ++#include <dirent.h> ++#include <fcntl.h> ++#include <limits.h> ++#include <stddef.h> ++#include <string> ++ ++#include "DtaAtaDrive.h" ++#include "DtaBlockStorageDevice.h" ++#include "DtaNvmeDrive.h" ++#include "DtaOpenBSD.h" ++#include "DtaSataDrive.h" ++#include "DtaScsiDrive.h" ++#include "NVMeStructures.h" ++#include "log.h" ++ ++const std::string DtaOS::name = "OpenBSD"; ++ ++DtaOS * ++DtaOS::getDtaOS() ++{ ++ return new DtaOpenBSD(); ++} ++ ++static bool ++rawWholeDiskName(const char *name) ++{ ++ const char *p; ++ ++ if (strncmp(name, "rsd", 3) != 0 && strncmp(name, "rwd", 3) != 0) ++ return false; ++ p = name + 3; ++ if (*p < '0' || *p > '9') ++ return false; ++ while (*p >= '0' && *p <= '9') ++ p++; ++ return p[0] == 'c' && p[1] == '\0'; ++} ++ ++static bool ++isWdDevice(const char *devref) ++{ ++ const char *name = strrchr(devref, '/'); ++ name = name == NULL ? devref : name + 1; ++ return strncmp(name, "rwd", 3) == 0; ++} ++ ++static bool ++scsiInquiry(int fd, bool evpd, unsigned char page, unsigned char *data, ++ size_t dataLen, size_t &dataUsed) ++{ ++ struct scsireq req; ++ ++ dataUsed = 0; ++ if (dataLen == 0 || dataLen > 255) ++ return false; ++ memset(&req, 0, sizeof(req)); ++ memset(data, 0, dataLen); ++ req.flags = SCCMD_READ; ++ req.timeout = 1000; ++ req.cmd[0] = 0x12; /* INQUIRY */ ++ req.cmd[1] = evpd ? 1 : 0; ++ req.cmd[2] = page; ++ req.cmd[4] = static_cast<unsigned char>(dataLen); ++ req.cmdlen = 6; ++ req.databuf = reinterpret_cast<caddr_t>(data); ++ req.datalen = dataLen; ++ req.senselen = SENSEBUFLEN; ++ if (ioctl(fd, SCIOCCOMMAND, &req) == -1 || req.retsts != SCCMD_OK) ++ return false; ++ dataUsed = std::min<size_t>(dataLen, req.datalen_used); ++ return true; ++} ++ ++static bool ++probeSCSI(int fd, bool &isATA, bool &isSAS) ++{ ++ unsigned char inquiry[96], pages[255]; ++ size_t used, pageLen; ++ ++ isATA = false; ++ isSAS = false; ++ if (!scsiInquiry(fd, false, 0, inquiry, sizeof(inquiry), used) || ++ used < 36) ++ return false; ++ isATA = memcmp(inquiry + 8, "ATA ", 8) == 0; ++ if (!scsiInquiry(fd, true, 0, pages, sizeof(pages), used) || used < 4) ++ return true; ++ pageLen = (static_cast<size_t>(pages[2]) << 8) | pages[3]; ++ pageLen = std::min(pageLen, used - 4); ++ for (size_t i = 0; i < pageLen; i++) { ++ if (pages[4 + i] == 0x89) ++ isATA = true; /* ATA information VPD page */ ++ if (pages[4 + i] == 0x90 || pages[4 + i] == 0x91) ++ isSAS = true; /* protocol-specific SAS pages */ ++ } ++ return true; ++} ++ ++static bool ++populateSCSIIdentity(int fd, DTA_DEVICE_INFO &info) ++{ ++ static const char hex[] = "0123456789abcdef"; ++ unsigned char vpd[255]; ++ std::string serial; ++ size_t used, pageLen, end, offset; ++ ++ /* ++ * Linux sedutil salts passwords with udev's ID_SERIAL_SHORT. For a ++ * SCSI disk, scsi_id normally derives that value from the logical-unit ++ * NAA descriptor in VPD page 0x83. Reproduce that value so passwords ++ * provisioned on Linux continue to authenticate on OpenBSD. ++ */ ++ if (scsiInquiry(fd, true, 0x83, vpd, sizeof(vpd), used) && used >= 4) { ++ pageLen = (static_cast<size_t>(vpd[2]) << 8) | vpd[3]; ++ end = std::min(used, pageLen + 4); ++ for (offset = 4; offset + 4 <= end; ) { ++ size_t identifierLen = vpd[offset + 3]; ++ size_t next = offset + 4 + identifierLen; ++ unsigned int codeSet = vpd[offset] & 0x0f; ++ unsigned int association = (vpd[offset + 1] >> 4) & 0x03; ++ unsigned int identifierType = vpd[offset + 1] & 0x0f; ++ ++ if (next > end) ++ break; ++ if (codeSet == 1 && association == 0 && ++ identifierType == 3 && identifierLen != 0) { ++ serial.reserve(identifierLen * 2); ++ for (size_t i = offset + 4; i < next; i++) { ++ serial.push_back(hex[vpd[i] >> 4]); ++ serial.push_back(hex[vpd[i] & 0x0f]); ++ } ++ break; ++ } ++ offset = next; ++ } ++ } ++ ++ /* Fall back to the trimmed unit serial from VPD page 0x80. */ ++ if (serial.empty() && ++ scsiInquiry(fd, true, 0x80, vpd, sizeof(vpd), used) && used >= 4) { ++ pageLen = (static_cast<size_t>(vpd[2]) << 8) | vpd[3]; ++ end = std::min(used, pageLen + 4); ++ offset = 4; ++ while (offset < end && (vpd[offset] == ' ' || vpd[offset] == '\0')) ++ offset++; ++ while (end > offset && (vpd[end - 1] == ' ' || vpd[end - 1] == '\0')) ++ end--; ++ serial.assign(reinterpret_cast<const char *>(vpd + offset), ++ end - offset); ++ } ++ if (serial.empty()) ++ return false; ++ ++ memset(info.serialNum, 0, sizeof(info.serialNum)); ++ memcpy(info.serialNum, serial.data(), ++ std::min(serial.size(), sizeof(info.serialNum))); ++ memset(info.passwordSalt, 0, sizeof(info.passwordSalt)); ++ memcpy(info.passwordSalt, serial.data(), ++ std::min(serial.size(), sizeof(info.passwordSalt))); ++ return true; ++} ++ ++OSDEVICEHANDLE ++DtaOpenBSD::openDeviceHandle(const char *devref, bool &accessDenied) ++{ ++ int fd; ++ ++ accessDenied = false; ++ fd = open(devref, O_RDWR | O_CLOEXEC); ++ if (fd == -1) { ++ if (errno == EACCES || errno == EPERM || errno == EROFS) ++ accessDenied = true; ++ else if (errno != ENOENT) { ++ LOG(E) << "Failed opening " << devref << ": " ++ << strerror(errno); ++ } ++ return INVALID_HANDLE_VALUE; ++ } ++ return handle(fd); ++} ++ ++void ++DtaOpenBSD::closeDeviceHandle(OSDEVICEHANDLE h) ++{ ++ if (h != INVALID_HANDLE_VALUE) ++ (void)close(handleDescriptor(h)); ++} ++ ++std::vector<std::string> ++DtaOpenBSD::generateDtaDriveDevRefs() ++{ ++ std::vector<std::string> devrefs; ++ DIR *dir; ++ struct dirent *entry; ++ ++ dir = opendir("/dev"); ++ if (dir == NULL) { ++ LOG(E) << "Cannot open /dev: " << strerror(errno); ++ return devrefs; ++ } ++ while ((entry = readdir(dir)) != NULL) { ++ struct stat st; ++ std::string path; ++ ++ if (!rawWholeDiskName(entry->d_name)) ++ continue; ++ path = std::string("/dev/") + entry->d_name; ++ if (stat(path.c_str(), &st) == 0 && S_ISCHR(st.st_mode)) ++ devrefs.push_back(path); ++ } ++ closedir(dir); ++ std::sort(devrefs.begin(), devrefs.end()); ++ return devrefs; ++} ++ ++void ++DtaOpenBSD::errorNoAccess(const char *devref) ++{ ++ if (devref == NULL) ++ LOG(E) << "Permission denied opening raw disks; run as root"; ++ else ++ LOG(E) << "Permission denied opening " << devref ++ << "; run as root"; ++} ++ ++static bool ++probeNVMe(int fd, unsigned char data[4096]) ++{ ++ struct nvme_pt_cmd pt; ++ ++ memset(&pt, 0, sizeof(pt)); ++ memset(data, 0, 4096); ++ pt.pt_opcode = NVME_IDENTIFY; ++ pt.pt_cdw10 = NVME_IDENTIFY_CNS_CTRL; ++ pt.pt_databuf = reinterpret_cast<caddr_t>(data); ++ pt.pt_databuflen = 4096; ++ return ioctl(fd, NVME_PASSTHROUGH_CMD, &pt) == 0; ++} ++ ++DtaOS::dictionary * ++DtaOpenBSD::getOSSpecificInformation(OSDEVICEHANDLE h, const char *devref, ++ InterfaceDeviceID &interfaceID, DTA_DEVICE_INFO &info) ++{ ++ dictionary *properties = new dictionary; ++ struct disklabel label; ++ unsigned char identify[4096]; ++ bool isATA, isSAS; ++ int fd = handleDescriptor(h); ++ ++ memset(&label, 0, sizeof(label)); ++ if (ioctl(fd, DIOCGDINFO, &label) == 0) ++ info.devSize = static_cast<uint64_t>(label.d_secperunit) * ++ label.d_secsize; ++ ++ if (probeNVMe(fd, identify)) { ++ info.devType = DEVICE_TYPE_NVME; ++ safecopy(info.serialNum, sizeof(info.serialNum), identify + 4, 20); ++ safecopy(info.modelNum, sizeof(info.modelNum), identify + 24, 40); ++ safecopy(info.firmwareRev, sizeof(info.firmwareRev), identify + 64, 8); ++ memcpy(interfaceID, identify, sizeof(interfaceID)); ++ memcpy(info.passwordSalt, info.serialNum, ++ sizeof(info.passwordSalt)); ++ (*properties)["Transport"] = "NVMe"; ++ } else if (isWdDevice(devref)) { ++ info.devType = DEVICE_TYPE_ATA; ++ (*properties)["Transport"] = "ATA"; ++ } else if (probeSCSI(fd, isATA, isSAS)) { ++ if (isATA) { ++ info.devType = DEVICE_TYPE_ATA; ++ (*properties)["Transport"] = "ATA/SAT"; ++ } else if (isSAS) { ++ (void)populateSCSIIdentity(fd, info); ++ info.devType = DEVICE_TYPE_SAS; ++ (*properties)["Transport"] = "SAS"; ++ } else { ++ (void)populateSCSIIdentity(fd, info); ++ info.devType = DEVICE_TYPE_SCSI; ++ (*properties)["Transport"] = "SCSI"; ++ } ++ } else { ++ /* ++ * Preserve the upstream SAT-then-SCSI fallback for devices which ++ * do not answer a standard SCSI INQUIRY (usually USB bridges). ++ */ ++ info.devType = DEVICE_TYPE_USB; ++ (*properties)["Transport"] = "USB/SAT"; ++ } ++ (*properties)["Device"] = devref; ++ return properties; ++} ++ ++void * ++DtaOpenBSD::alloc_aligned_MIN_BUFFER_LENGTH_buffer() ++{ ++ void *buffer = NULL; ++ size_t length = (MIN_BUFFER_LENGTH + IO_BUFFER_ALIGNMENT - 1) / ++ IO_BUFFER_ALIGNMENT * IO_BUFFER_ALIGNMENT; ++ ++ if (posix_memalign(&buffer, IO_BUFFER_ALIGNMENT, length) != 0) ++ return NULL; ++ return buffer; ++} ++ ++void ++DtaOpenBSD::free_aligned_MIN_BUFFER_LENGTH_buffer(void *buffer) ++{ ++ free(buffer); ++} ++ ++int ++DtaOpenBSD::PerformATACommand_via_HD(OSDEVICEHANDLE h, ATACOMMAND cmd, ++ uint8_t securityProtocol, uint16_t comID, void *buffer, ++ unsigned int &bufferlen) ++{ ++ struct atareq req; ++ ++ if (h == INVALID_HANDLE_VALUE) ++ return EBADF; ++ memset(&req, 0, sizeof(req)); ++ req.command = static_cast<u_char>(cmd); ++ req.databuf = reinterpret_cast<caddr_t>(buffer); ++ req.datalen = bufferlen; ++ req.timeout = cmd == IDENTIFY_DEVICE ? 1000 : 60000; ++ ++ switch (cmd) { ++ case IDENTIFY_DEVICE: ++ req.flags = ATACMD_READ; ++ break; ++ case TRUSTED_RECEIVE: ++ req.flags = ATACMD_READ; ++ req.features = securityProtocol; ++ req.sec_count = static_cast<u_char>(bufferlen / 512); ++ req.cylinder = comID; ++ break; ++ case TRUSTED_SEND: ++ req.flags = ATACMD_WRITE; ++ req.features = securityProtocol; ++ req.sec_count = static_cast<u_char>(bufferlen / 512); ++ req.cylinder = comID; ++ break; ++ default: ++ return EINVAL; ++ } ++ ++ if (ioctl(handleDescriptor(h), ATAIOCCOMMAND, &req) == -1) ++ return errno; ++ if (req.retsts != ATACMD_OK) { ++ LOG(D4) << "ATA command failed: retsts=" ++ << static_cast<unsigned int>(req.retsts) << " error=" ++ << static_cast<unsigned int>(req.error); ++ return EIO; ++ } ++ if (cmd == IDENTIFY_DEVICE && ++ std::all_of(static_cast<unsigned char *>(buffer), ++ static_cast<unsigned char *>(buffer) + bufferlen, ++ [](unsigned char byte) { return byte == 0; })) ++ return EIO; ++ bufferlen = req.datalen; ++ return 0; ++} ++ ++int ++DtaOpenBSD::PerformSCSICommand(OSDEVICEHANDLE h, int direction, ++ uint8_t *cdb, unsigned char cdbLen, void *buffer, ++ unsigned int &bufferlen, unsigned char *sense, ++ unsigned char &senseLen, SCSI_STATUS_CODE *maskedStatus, ++ unsigned int timeout) ++{ ++ struct scsireq req; ++ size_t copiedSense; ++ ++ if (h == INVALID_HANDLE_VALUE) ++ return -EBADF; ++ if (cdb == NULL || cdbLen > CMDBUFLEN) ++ return -EINVAL; ++ ++ memset(&req, 0, sizeof(req)); ++ req.flags = direction == PSC_FROM_DEV ? SCCMD_READ : SCCMD_WRITE; ++ req.timeout = timeout; ++ memcpy(req.cmd, cdb, cdbLen); ++ req.cmdlen = cdbLen; ++ req.databuf = reinterpret_cast<caddr_t>(buffer); ++ req.datalen = bufferlen; ++ req.senselen = static_cast<u_char>(std::min<size_t>(senseLen, ++ SENSEBUFLEN)); ++ ++ if (ioctl(handleDescriptor(h), SCIOCCOMMAND, &req) == -1) ++ return -errno; ++ ++ bufferlen = req.datalen_used; ++ copiedSense = std::min<size_t>(senseLen, req.senselen_used); ++ if (sense != NULL && copiedSense != 0) ++ memcpy(sense, req.sense, copiedSense); ++ senseLen = static_cast<unsigned char>(copiedSense); ++ if (maskedStatus != NULL) ++ *maskedStatus = static_cast<SCSI_STATUS_CODE>(req.status >> 1); ++ ++ if (req.retsts == SCCMD_OK || req.retsts == SCCMD_SENSE) ++ return 0; ++ if (req.retsts == SCCMD_TIMEOUT) ++ return -ETIMEDOUT; ++ return -EIO; ++} ++ ++int ++DtaOpenBSD::PerformNVMeCommand(OSDEVICEHANDLE h, uint8_t *pcmd, ++ uint32_t *status) ++{ ++ struct nvme_admin_cmd *cmd; ++ struct nvme_pt_status ptStatus; ++ struct nvme_pt_cmd pt; ++ ++ if (h == INVALID_HANDLE_VALUE) { ++ errno = EBADF; ++ return -1; ++ } ++ if (pcmd == NULL) { ++ errno = EINVAL; ++ return -1; ++ } ++ cmd = reinterpret_cast<struct nvme_admin_cmd *>(pcmd); ++ ++ memset(&pt, 0, sizeof(pt)); ++ memset(&ptStatus, 0, sizeof(ptStatus)); ++ pt.pt_opcode = cmd->opcode; ++ pt.pt_nsid = cmd->nsid; ++ pt.pt_cdw10 = cmd->cdw10; ++ pt.pt_cdw11 = cmd->cdw11; ++ pt.pt_cdw12 = cmd->cdw12; ++ pt.pt_cdw13 = cmd->cdw13; ++ pt.pt_cdw14 = cmd->cdw14; ++ pt.pt_cdw15 = cmd->cdw15; ++ pt.pt_databuf = reinterpret_cast<caddr_t>( ++ static_cast<uintptr_t>(cmd->addr)); ++ pt.pt_databuflen = cmd->data_len; ++ pt.pt_status = reinterpret_cast<caddr_t>(&ptStatus); ++ pt.pt_statuslen = sizeof(ptStatus); ++ ++ if (ioctl(handleDescriptor(h), NVME_PASSTHROUGH_CMD, &pt) == -1) ++ return -1; ++ if (status != NULL) ++ *status = static_cast<uint32_t>(ptStatus.ps_flags); ++ return 0; ++} ++ ++DtaDrive * ++DtaDrive::getDtaDrive(Protocol protocol, const char *devref, ++ DTA_DEVICE_INFO &deviceInfo) ++{ ++ switch (protocol) { ++ case AtaDrive: ++ return DtaAtaDrive::getDtaAtaDrive(devref, deviceInfo); ++ case NvmeDrive: ++ return DtaNvmeDrive::getDtaNvmeDrive(devref, deviceInfo); ++ case ScsiDrive: ++ return DtaScsiDrive::getDtaScsiDrive(devref, deviceInfo); ++ case SataDrive: ++ return DtaSataDrive::getDtaSataDrive(devref, deviceInfo); ++ default: ++ return NULL; ++ } ++} ++ ++DtaAtaDrive * ++DtaAtaDrive::getDtaOSSpecificAtaDrive(OSDEVICEHANDLE h, bool translated) ++{ ++ return new DtaAtaDrive(h, translated); ++} ++ ++DtaNvmeDrive * ++DtaNvmeDrive::getDtaOSSpecificNvmeDrive(OSDEVICEHANDLE h) ++{ ++ return new DtaNvmeDrive(h); ++} ++ ++DtaScsiDrive * ++DtaScsiDrive::getDtaOSSpecificScsiDrive(OSDEVICEHANDLE h) ++{ ++ return new DtaScsiDrive(h); ++} ++ ++DtaSataDrive * ++DtaSataDrive::getDtaOSSpecificSataDrive(OSDEVICEHANDLE h) ++{ ++ return new DtaSataDrive(h); ++} Index: sysutils/sedutil/patches/patch-Common_DtaOpenBSD_h --- /dev/null +++ sysutils/sedutil/patches/patch-Common_DtaOpenBSD_h @@ -0,0 +1,33 @@ +Index: Common/DtaOpenBSD.h +--- Common/DtaOpenBSD.h.orig ++++ Common/DtaOpenBSD.h +@@ -0,0 +1,29 @@ ++/* OpenBSD storage passthrough backend for sedutil-cli. */ ++#pragma once ++ ++#include "DtaOS.h" ++ ++class DtaOpenBSD : public DtaOS { ++public: ++ using DtaOS::DtaOS; ++ ++ OSDEVICEHANDLE openDeviceHandle(const char *, bool &) override; ++ void closeDeviceHandle(OSDEVICEHANDLE) override; ++ std::vector<std::string> generateDtaDriveDevRefs() override; ++ void errorNoAccess(const char *) override; ++ ++ dictionary *getOSSpecificInformation(OSDEVICEHANDLE, const char *, ++ InterfaceDeviceID &, DTA_DEVICE_INFO &) override; ++ ++ void *alloc_aligned_MIN_BUFFER_LENGTH_buffer() override; ++ void free_aligned_MIN_BUFFER_LENGTH_buffer(void *) override; ++ ++ int PerformATACommand_via_HD(OSDEVICEHANDLE, ATACOMMAND, uint8_t, ++ uint16_t, void *, unsigned int &) override; ++ ++ int PerformSCSICommand(OSDEVICEHANDLE, int, uint8_t *, unsigned char, ++ void *, unsigned int &, unsigned char *, unsigned char &, ++ SCSI_STATUS_CODE *, unsigned int) override; ++ ++ int PerformNVMeCommand(OSDEVICEHANDLE, uint8_t *, uint32_t *) override; ++}; Index: sysutils/sedutil/patches/patch-Common_ParseATIdentify_cpp --- /dev/null +++ sysutils/sedutil/patches/patch-Common_ParseATIdentify_cpp @@ -0,0 +1,22 @@ +Remove a dependency on the private P_16_COPY macro from Berkeley DB. That +macro is not part of db.h's public interface and is not exposed by OpenBSD. + +Index: Common/ParseATIdentify.cpp +--- Common/ParseATIdentify.cpp.orig ++++ Common/ParseATIdentify.cpp +@@ -10,11 +10,11 @@ + + #include "ParseATIdentify.h" + +-// Steal P_16_COPY, a very useful internal macro from db.h +-#define __DBINTERFACE_PRIVATE +-#include <db.h> +-#undef __DBINTERFACE_PRIVATE + #include <string.h> ++#define P_16_COPY(a, b) do { \ ++ ((unsigned char *)&(b))[0] = ((const unsigned char *)&(a))[1]; \ ++ ((unsigned char *)&(b))[1] = ((const unsigned char *)&(a))[0]; \ ++} while (0) + #include <algorithm> + + void parseATIdentifyResponse( const ATA_IDENTIFY_DEVICE_RESPONSE * presp, DTA_DEVICE_INFO * pdi) Index: sysutils/sedutil/patches/patch-Common_Version_h --- /dev/null +++ sysutils/sedutil/patches/patch-Common_Version_h @@ -0,0 +1,5 @@ +Index: Common/Version.h +--- Common/Version.h.orig ++++ Common/Version.h +@@ -0,0 +1 @@ ++#define GIT_VERSION "1.49.13-openbsd" Index: sysutils/sedutil/patches/patch-Common_os_h --- /dev/null +++ sysutils/sedutil/patches/patch-Common_os_h @@ -0,0 +1,51 @@ +Index: Common/os.h +--- Common/os.h.orig ++++ Common/os.h +@@ -0,0 +1,47 @@ ++/* OpenBSD operating-system definitions for sedutil-cli. */ ++#pragma once ++ ++#include <sys/types.h> ++ ++#include <arpa/inet.h> ++#include <assert.h> ++#include <errno.h> ++#include <stdint.h> ++#include <stdio.h> ++#include <stdlib.h> ++#include <string.h> ++#include <unistd.h> ++ ++#include "DtaConstants.h" ++#include "log.h" ++ ++#ifndef TRUE ++#define TRUE 1 ++#endif ++#ifndef FALSE ++#define FALSE 0 ++#endif ++ ++#define SNPRINTF snprintf ++#define DEVICEEXAMPLE "/dev/rsd0c" ++ ++/* These are retained for code which still uses the legacy scan macros. */ ++#define DEVICEMASK snprintf(devname, 23, "/dev/rsd%dc", i) ++#define DEVICEMASKN snprintf(devname, 23, "/dev/rsd%dc", j) ++ ++#define __unimplemented__ { throw __PRETTY_FUNCTION__; } ++ ++static inline void ++osmsSleep(uint32_t milliseconds) ++{ ++ (void)usleep(milliseconds * 1000); ++} ++ ++typedef void *OSDEVICEHANDLE; ++#define INVALID_HANDLE_VALUE (reinterpret_cast<OSDEVICEHANDLE>(-1)) ++ ++#define handle(descriptor) \ ++ (reinterpret_cast<OSDEVICEHANDLE>(static_cast<uintptr_t>(descriptor))) ++#define handleDescriptor(value) \ ++ (static_cast<int>(static_cast<unsigned int>( \ ++ reinterpret_cast<uintptr_t>(value)))) Index: sysutils/sedutil/patches/patch-Common_sedutil_cpp --- /dev/null +++ sysutils/sedutil/patches/patch-Common_sedutil_cpp @@ -0,0 +1,14 @@ +Propagate the parsed -t option to the device, as is already done for -n. +Without this, host-hashed credentials remain ASCII instead of being decoded. + +Index: Common/sedutil.cpp +--- Common/sedutil.cpp.orig ++++ Common/sedutil.cpp +@@ -334,6 +334,7 @@ main(int argc, char * argv[]) + if (d!=NULL) { + // initialize instance variables no_hash_passwords and output_format + d->no_hash_passwords = opts.no_hash_passwords; ++ d->translate_req = opts.translate_req; + result = main_actions(argc, argv, d, opts); + } + break; Index: sysutils/sedutil/patches/patch-Makefile_am --- /dev/null +++ sysutils/sedutil/patches/patch-Makefile_am @@ -0,0 +1,94 @@ +Index: Makefile.am +--- Makefile.am.orig ++++ Makefile.am +@@ -1,8 +1,8 @@ + AUTOMAKE_OPTIONS = foreign subdir-objects +-WERROR = -Werror ++WERROR = + AM_CFLAGS = -Wall $(WERROR) -std=c11 +-AM_CXXFLAGS = -Wall $(WERROR) -std=c++11 -I./linux \ +- -I$(srcdir)/Common -I$(srcdir)/Common/pbkdf2 -I$(srcdir)/linux -I$(srcdir)/LinuxPBA ++AM_CXXFLAGS = -Wall $(WERROR) -std=c++11 \ ++ -I$(srcdir)/Common -I$(srcdir)/Common/pbkdf2 + + SEDUTIL_COMMON_CODE = \ + Common/ATAStructures.h \ +@@ -70,21 +70,10 @@ Common/ParseDiscovery0Features.h \ + Common/SCSICmds_INQUIRY_Definitions.h + +-SEDUTIL_LINUX_CODE = \ +-linux/db.h \ +-linux/os.h \ +-linux/DtaLinux.cpp \ +-linux/DtaLinux.h \ +-linux/DtaLinuxDriveFactory.cpp \ +-linux/DtaLinuxBlockStorageDevice.cpp \ +-linux/DtaLinuxBlockStorageDevice.h \ +-linux/DtaLinuxAtaDrive.cpp \ +-linux/DtaLinuxAtaDrive.h \ +-linux/DtaLinuxNvmeDrive.cpp \ +-linux/DtaLinuxNvmeDrive.h \ +-linux/DtaLinuxSataDrive.cpp \ +-linux/DtaLinuxSataDrive.h \ +-linux/DtaLinuxScsiDrive.cpp \ +-linux/DtaLinuxScsiDrive.h ++SEDUTIL_OPENBSD_CODE = \ ++Common/os.h \ ++Common/Version.h \ ++Common/DtaOpenBSD.cpp \ ++Common/DtaOpenBSD.h + + SEDUTIL_CUSTOMIZATIONS_COMMON_CODE = \ + Customizations/Common/DtaAuthorizeSedutilExecution.cpp \ +@@ -107,11 +96,11 @@ Common/pbkdf2/handy.h \ + Common/pbkdf2/tassert.h + +-sbin_PROGRAMS = sedutil-cli linuxpba ++sbin_PROGRAMS = sedutil-cli + + sedutil_cli_SOURCES = \ + Common/DtaOptions.cpp \ + Common/DtaOptions.h \ +-$(SEDUTIL_LINUX_CODE) \ ++$(SEDUTIL_OPENBSD_CODE) \ + $(SEDUTIL_COMMON_CODE) \ + $(SEDUTIL_CUSTOMIZATIONS_COMMON_CODE) \ + $(SEDUTIL_LOG_CODE) \ +@@ -120,37 +109,10 @@ $(SEDUTIL_CIFRA_CODE) \ + Common/sedutil.cpp + +-LDADD = -lsystemd +- +-CLEANFILES = linux/Version.h +- +-BUILT_SOURCES = linux/Version.h +-# +- +-linuxpba_SOURCES = \ +-LinuxPBA/GetPassPhrase.cpp \ +-LinuxPBA/GetPassPhrase.h \ +-LinuxPBA/UnlockSEDs.cpp \ +-LinuxPBA/UnlockSEDs.h \ +-$(SEDUTIL_LINUX_CODE) \ +-$(SEDUTIL_COMMON_CODE) \ +-$(SEDUTIL_CUSTOMIZATIONS_COMMON_CODE) \ +-$(SEDUTIL_LOG_CODE) \ +-$(SEDUTIL_CIFRA_CODE) \ +-LinuxPBA/LinuxPBA.cpp +- + EXTRA_DIST = \ +-Customizations/linux/CLI/GitVersion.sh \ +-linux/PSIDRevert_LINUX.txt \ +-linux/TestSuite.sh \ + README.md docs/sedutil-cli.8 + + man_MANS = docs/sedutil-cli.8 + +-linux/Version.h: +- $(srcdir)/Customizations/linux/CLI/GitVersion.sh > linux/Version.h +- +-.INTERMEDIATE: linux/Version.h +- + maintainer-clean-local: + rm config.status configure config.log + rm Makefile Index: sysutils/sedutil/patches/patch-docs_sedutil-cli_8 --- /dev/null +++ sysutils/sedutil/patches/patch-docs_sedutil-cli_8 @@ -0,0 +1,101 @@ +Use valid man(7) markup, document OpenBSD device names and explain the +kernel limitation affecting NVMe Security Send and Security Receive. + +Index: docs/sedutil-cli.8 +--- docs/sedutil-cli.8.orig ++++ docs/sedutil-cli.8 +@@ -1,28 +1,29 @@ + .\" Manpage for sedutil-cli. +-.TH SEDUTIL\-CLI 8 "18 Feb 2016" "0.12" "sedutil-cli man page" ++.TH SEDUTIL\-CLI 8 "February 18, 2016" "1.49.13" "sedutil-cli man page" + .SH NAME + sedutil-cli \- util to manage TCG Opal 2.0 self encrypting drives +- + .SH SYNOPSIS + sedutil\-cli <\-v> <\-n> <action> <options> <device> +- + .SH DESCRIPTION + sedutil-cli is a utility to manage self encrypting drives that conform + to the Trusted Computing Group (TCG) OPAL 2.0 SSC specification. +- +-In Linux libata.allow_tpm must be set to 1. Either via adding +-libata.allow_tpm=1 to the kernel flags at boot time or changing the +-contents of /sys/module/libata/parameters/allow_tpm to a from a +-"0" to a "1" on a running system. +- ++.PP ++On OpenBSD, use the raw whole-disk device, such as ++.I /dev/rsd0c ++or ++.IR /dev/rwd0c . ++Direct device access normally requires root privileges. ++.PP ++OpenBSD supports the required passthrough commands for ATA and SCSI/SAS/SAT ++devices. NVMe disks can be identified, but the kernel currently rejects ++the NVMe Security Send and Security Receive commands required to manage ++their Opal state. + .SH OPTIONS + .SS General Options +-.TP + .IP "\-v (optional)" + increase verbosity, one to five v's + .IP "\-n (optional)" + no password hashing. Passwords will be sent in clear text! +- + .SS Actions + .IP \-\-scan + Scans the devices on the system identifying Opal compliant devices +@@ -45,13 +47,15 @@ Erase a Locking Range, 0 = GLobal 1..n = LRn + .IP "\-\-setupLockingRange <0...n> <RangeStart> <RangeLength> <password> <device>" + Setup a new Locking Range, 0 = GLobal 1..n = LRn + .IP "\-\-initialSetup <SIDpassword> <device>" +-Setup the device for use with sedutil, <SIDpassword> is new SID and Admin1 password ++Setup the device for use with sedutil; <SIDpassword> is the new SID and ++Admin1 password. + .IP "\-\-setSIDPassword <SIDpassword> <newSIDpassword> <device>" + Change the SID password + .IP "\-\-setAdmin1Pwd <Admin1password> <newAdmin1password> <device>" + Change the Admin1 password + .IP "\-\-setPassword <oldpassword, "" for MSID> <userid> <newpassword> <device>" +-Change the Enterprise password for userid, "EraseMaster" or "BandMaster<n>", 0 <= n <= 1023 ++Change the Enterprise password for userid, "EraseMaster" or ++"BandMaster<n>", 0 <= n <= 1023. + .IP "\-\-setLockingRange <0...n> <RW|RO|LK> <Admin1password> <device>" + Set the status of a Locking Range, 0 = GLobal 1..n = LRn + .IP "\-\-enableLockingRange <0...n> <Admin1password> <device>" +@@ -70,27 +75,27 @@ set the device back to factory defaults. + .IP "\-\-revertNoErase <Admin1password> <device>" + deactivate the Locking SP without erasing the data on GLOBAL RANGE *ONLY* + .IP "\-\---yesIreallywanttoERASEALLmydatausingthePSID <PSID> <device>" +-revert the device using the PSID. ++revert the device using the PSID. + .B *ERASING* *ALL* the data + .IP "\-\-printDefaultPassword <device>" + print MSID +- + .SH EXAMPLES + .EX + sedutil-cli --scan + .EE + .EX +-sedutil-cli --query /dev/sdc ++sedutil-cli --query /dev/rsd0c + .EE + .EX +-sedutil-cli --yesIreallywanttoERASEALLmydatausingthePSID <PSIDALLCAPSNODASHED> /dev/sdc ++sedutil-cli --yesIreallywanttoERASEALLmydatausingthePSID <PSIDALLCAPSNODASHED> /dev/rsd0c + .EE + .EX +-sedutil-cli --initialSetup <newSIDpassword> /dev/sdc ++sedutil-cli --initialSetup <newSIDpassword> /dev/rsd0c + .EE +- + .SH BUGS + Sleep (S3) is not supported. +- + .SH AUTHOR +-The tool was developed by Bright Plaza Inc. <[email protected]>. This man page was written by Jan Luca Naumann <[email protected]>. ++The tool was developed by Bright Plaza Inc. ++<[email protected]>. ++This man page was written by Jan Luca Naumann ++<[email protected]>. Index: sysutils/sedutil/pkg/DESCR --- /dev/null +++ sysutils/sedutil/pkg/DESCR @@ -0,0 +1,6 @@ +sedutil-cli manages Trusted Computing Group (TCG) Opal, +Enterprise, Pyrite, and Ruby self-encrypting drives. It can inspect, +provision, lock, unlock, and revert supported drives. + +This package contains only the command-line utility. Pre-Boot +Authentication (PBA) programs and images are intentionally omitted. Index: sysutils/sedutil/pkg/PLIST --- /dev/null +++ sysutils/sedutil/pkg/PLIST @@ -0,0 +1,3 @@ +@man man/man8/sedutil-cli.8 +@bin sbin/sedutil-cli +share/doc/pkg-readmes/${PKGSTEM} Index: sysutils/sedutil/pkg/README --- /dev/null +++ sysutils/sedutil/pkg/README @@ -0,0 +1,21 @@ ++----------------------------------------------------------------------- +| Running ${PKGSTEM} on OpenBSD ++----------------------------------------------------------------------- + +sedutil-cli sends security commands directly to storage devices. It must +normally be run as root and a mistaken command can make data inaccessible. +Keep tested backups and record recovery credentials before provisioning a +drive. + +Use OpenBSD raw whole-disk device names, for example /dev/rsd0c or +/dev/rwd0c. + +ATA drives and SCSI/SAS/SAT devices use OpenBSD's ATA and SCSI passthrough +interfaces. NVMe disks can be identified, but OpenBSD's NVMe passthrough +interface currently rejects the Security Send and Security Receive admin +commands required to manage Opal state. + +The -n option accepts a password without applying PBKDF2. With -n -t, a +64-character hexadecimal string is decoded into the 32-byte host-hashed +password expected by the drive. This can be used to authenticate credentials +provisioned by sedutil versions that selected a different device salt.
