Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import java.security.Provider;

public class InstallBouncyCastle {
private static final Provider PROVIDER;

public static void installProvider() throws Exception {
if (PROVIDER != null) return;
PROVIDER = new BouncyCastleProvider();
Expand All @@ -66,4 +66,4 @@ Go ahead, file issues, make pull requests. There is an automated build process

Currently setup to build in the NetBeans IDE. Automated checking is performed using the [COSE Examples](https://github.com/cose-wg/Examples) as part of the suite.

The examples are located by the following method. 1) If 'c:\\Projects\\cose\\" exists then it uses that as the directory to look in for the examples. 2) It expects that the examples are in the same directory as the pom.xml file.
The examples are imported into `src/test/resources/Examples`.
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.augustcellars.cose</groupId>
<artifactId>cose-java</artifactId>
<version>1.1.0</version>
<version>1.1.1-SNAPSHOT</version>

<name>com.augustcellars.cose:cose-java</name>
<description>A Java implementation that supports the COSE secure message specification.</description>
Expand Down Expand Up @@ -38,7 +38,7 @@
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -139,7 +139,7 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
Expand All @@ -157,7 +157,7 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand All @@ -183,7 +183,7 @@
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>

</plugins>
</build>
</profile>
Expand All @@ -192,7 +192,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<reporting>
<plugins>
<plugin>
Expand All @@ -203,4 +203,4 @@
</plugins>
</reporting>
</project>

25 changes: 25 additions & 0 deletions src/main/java/COSE/CryptoContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package COSE;


import java.security.Provider;

/**
* Specify which JCA Provider to use for signing and verifying messages
*/
public class CryptoContext {

private Provider provider;

public CryptoContext(Provider provider) {
this.provider = provider;
}

public Provider getProvider() {
return provider;
}

public void setProvider(Provider provider) {
this.provider = provider;
}

}
45 changes: 26 additions & 19 deletions src/main/java/COSE/Encrypt0Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public class Encrypt0Message extends EncryptCommon {
public Encrypt0Message() {
this(true, true);
}

/**
* Create a Encrypt0Message object. This object corresponds to the encrypt
message format in COSE.
*
*
* @param emitTag is the leading CBOR tag emitted
* @param emitContent is the content emitted
*/
Expand All @@ -38,11 +38,18 @@ public Encrypt0Message(boolean emitTag, boolean emitContent) {
this.emitTag = emitTag;
this.emitContent = emitContent;
}


/**
* Gets the {@link CryptoContext} to set a different JCA Provider
*/
public CryptoContext getCryptoContext() {
return cryptoContext;
}

@Override
public void DecodeFromCBORObject(CBORObject obj) throws CoseException {
if (obj.size() != 3) throw new CoseException("Invalid Encrypt0 structure");

if (obj.get(0).getType() == CBORType.ByteString) {
if (obj.get(0).GetByteString().length == 0) {
rgbProtected = new byte[0];
Expand All @@ -53,54 +60,54 @@ public void DecodeFromCBORObject(CBORObject obj) throws CoseException {
objProtected = CBORObject.DecodeFromBytes(rgbProtected);
if (objProtected.getType() != CBORType.Map) throw new CoseException("Invalid Encrypt0 structure");
}

}
else throw new CoseException("Invalid Encrypt0 structure");

if(obj.get(1).getType() == CBORType.Map) objUnprotected = obj.get(1);
else throw new CoseException("Invalid Encrypt0 structure");

if (obj.get(2).getType() == CBORType.ByteString) rgbEncrypt = obj.get(2).GetByteString();
else if (!obj.get(2).isNull()) throw new CoseException("Invalid Encrypt0 structure");


}

/**
* Internal function used to construct the CBORObject
* Internal function used to construct the CBORObject
* @return the constructed CBORObject
* @throws CoseException if the content has not yet been encrypted
*/
@Override
protected CBORObject EncodeCBORObject() throws CoseException {
if (rgbEncrypt == null) throw new CoseException("Encrypt function not called");

CBORObject obj = CBORObject.NewArray();
if (objProtected.size() > 0) obj.Add(objProtected.EncodeToBytes());
else obj.Add(CBORObject.FromObject(new byte[0]));

obj.Add(objUnprotected);

if (emitContent) obj.Add(rgbEncrypt);
else obj.Add(CBORObject.Null);

return obj;
}

/**
* Decrypt the message using the passed in key.
*
*
* @param rgbKey key for decryption
* @return the decrypted content
* @throws CoseException - Error during decryption
*/
public byte[] decrypt(byte[] rgbKey) throws CoseException {
return super.decryptWithKey(rgbKey);
}

/**
* Encrypt the message using the passed in key.
*
*
* @param rgbKey key used for encryption
* @throws CoseException - Error during decryption
* @throws IllegalStateException - Error during decryption
Expand Down
Loading