1717import java .util .Base64 ;
1818import java .util .List ;
1919import java .util .stream .Collectors ;
20+ import java .util .stream .Stream ;
2021import org .eclipse .biscuit .crypto .BlockSignatureBuffer ;
2122import org .eclipse .biscuit .crypto .KeyDelegate ;
2223import org .eclipse .biscuit .crypto .KeyPair ;
@@ -36,19 +37,16 @@ public class UnverifiedBiscuit {
3637 protected final List <Block > blocks ;
3738 protected final SymbolTable symbolTable ;
3839 protected final SerializedBiscuit serializedBiscuit ;
39- protected final List <byte []> revocationIds ;
4040
4141 UnverifiedBiscuit (
4242 Block authority ,
4343 List <Block > blocks ,
4444 SymbolTable symbolTable ,
45- SerializedBiscuit serializedBiscuit ,
46- List <byte []> revocationIds ) {
45+ SerializedBiscuit serializedBiscuit ) {
4746 this .authority = authority ;
4847 this .blocks = blocks ;
4948 this .symbolTable = symbolTable ;
5049 this .serializedBiscuit = serializedBiscuit ;
51- this .revocationIds = revocationIds ;
5250 }
5351
5452 /**
@@ -98,9 +96,7 @@ private static UnverifiedBiscuit fromSerializedBiscuit(
9896 Block authority = t ._1 ;
9997 ArrayList <Block > blocks = t ._2 ;
10098
101- List <byte []> revocationIds = ser .revocationIdentifiers ();
102-
103- return new UnverifiedBiscuit (authority , blocks , symbolTable , ser , revocationIds );
99+ return new UnverifiedBiscuit (authority , blocks , symbolTable , ser );
104100 }
105101
106102 /**
@@ -139,17 +135,15 @@ public org.eclipse.biscuit.token.builder.Block createBlock() {
139135 * @return
140136 */
141137 public UnverifiedBiscuit attenuate (
142- org .eclipse .biscuit .token .builder .Block block , Algorithm algorithm ) throws Error {
138+ org .eclipse .biscuit .token .builder .Block block , Algorithm algorithm ) throws Error {
143139 SecureRandom rng = new SecureRandom ();
144140 KeyPair keypair = KeyPair .generate (algorithm , rng );
145141 SymbolTable builderSymbols = new SymbolTable (this .symbolTable );
146142 return attenuate (rng , keypair , block .build (builderSymbols ));
147143 }
148144
149145 public UnverifiedBiscuit attenuate (
150- final SecureRandom rng ,
151- final KeyPair keypair ,
152- org .eclipse .biscuit .token .builder .Block block )
146+ final SecureRandom rng , final KeyPair keypair , org .eclipse .biscuit .token .builder .Block block )
153147 throws Error {
154148 SymbolTable builderSymbols = new SymbolTable (this .symbolTable );
155149 return attenuate (rng , keypair , block .build (builderSymbols ));
@@ -189,20 +183,25 @@ private UnverifiedBiscuit attenuate(final SecureRandom rng, final KeyPair keypai
189183 blocks .add (block );
190184 SerializedBiscuit container = containerRes .get ();
191185
192- List <byte []> revocationIds = container .revocationIdentifiers ();
193-
194- return new UnverifiedBiscuit (
195- copiedBiscuit .authority , blocks , symbols , container , revocationIds );
186+ return new UnverifiedBiscuit (copiedBiscuit .authority , blocks , symbols , container );
196187 }
197188
198189 // FIXME: attenuate 3rd Party
199190
200191 public List <RevocationIdentifier > revocationIdentifiers () {
201- return this .revocationIds .stream ()
192+ return this .serializedBiscuit . revocationIdentifiers () .stream ()
202193 .map (RevocationIdentifier ::fromBytes )
203194 .collect (Collectors .toList ());
204195 }
205196
197+ public List <Option <PublicKey >> externalPublicKeys () {
198+ return Stream .<Option <PublicKey >>concat (
199+ Stream .of (Option .none ()),
200+ this .serializedBiscuit .getBlocks ().stream ()
201+ .map (b -> b .getExternalSignature ().map (ExternalSignature ::getKey )))
202+ .collect (Collectors .toList ());
203+ }
204+
206205 public List <List <Check >> getChecks () {
207206 ArrayList <List <Check >> l = new ArrayList <>();
208207 l .add (new ArrayList <>(this .authority .getChecks ()));
@@ -237,6 +236,26 @@ public Option<Integer> getRootKeyId() {
237236 return this .serializedBiscuit .getRootKeyId ();
238237 }
239238
239+ public int blockCount () {
240+ return 1 + blocks .size ();
241+ }
242+
243+ public Option <PublicKey > blockExternalKey (int index ) {
244+ if (index == 0 ) {
245+ return authority .getExternalKey ();
246+ } else {
247+ return blocks .get (index - 1 ).getExternalKey ();
248+ }
249+ }
250+
251+ public List <PublicKey > blockPublicKeys (int index ) {
252+ if (index == 0 ) {
253+ return authority .getPublicKeys ();
254+ } else {
255+ return blocks .get (index - 1 ).getPublicKeys ();
256+ }
257+ }
258+
240259 /** Generates a third party block request from a token */
241260 public ThirdPartyBlockRequest thirdPartyRequest () {
242261 PublicKey previousKey ;
@@ -304,9 +323,7 @@ public UnverifiedBiscuit appendThirdPartyBlock(
304323 }
305324 blocks .add (block );
306325
307- List <byte []> revocationIds = container .revocationIdentifiers ();
308- return new UnverifiedBiscuit (
309- copiedBiscuit .authority , blocks , symbols , container , revocationIds );
326+ return new UnverifiedBiscuit (copiedBiscuit .authority , blocks , symbols , container );
310327 }
311328
312329 /** Prints a token's content */
0 commit comments