bwLehrpool Masterserver
Manages authentication and sharing of virtual machines between participating institutions
LocalOrganization.java
Go to the documentation of this file.
1 package org.openslx.imagemaster.db.models;
2 
3 import java.math.BigInteger;
4 import java.security.NoSuchAlgorithmException;
5 import java.security.PublicKey;
6 import java.security.spec.InvalidKeySpecException;
7 
8 import org.apache.logging.log4j.LogManager;
9 import org.apache.logging.log4j.Logger;
10 import org.openslx.encryption.AsymKeyHolder;
11 
12 public class LocalOrganization
13 {
14 
15  private static final Logger LOGGER = LogManager.getLogger( LocalOrganization.class );
16 
17  private PublicKey publickey;
18 
19  private String publickeyString;
20 
21  private String name;
22 
28  public PublicKey getPubkey()
29  {
30  if ( publickey == null && publickeyString != null ) {
31  String parts[] = publickeyString.split( " " );
32  BigInteger mod = null;
33  BigInteger exp = null;
34  for ( int i = 0; i < parts.length; ++i ) {
35  if ( parts[i].startsWith( "mod:" ) ) {
36  // modulus found.
37  mod = new BigInteger( parts[i].substring( 4 ) );
38  }
39  if ( parts[i].startsWith( "exp:" ) ) {
40  // exponent found.
41  exp = new BigInteger( parts[i].substring( 4 ) );
42  }
43  }
44  if ( mod == null ) {
45  LOGGER.error( "No modulus for building public key was found." );
46  return null;
47  }
48  if ( exp == null ) {
49  LOGGER.error( "No public exponent for building public key was found." );
50  return null;
51  }
52  try {
53  publickey = new AsymKeyHolder( null, exp, mod ).getPublicKey();
54  } catch ( InvalidKeySpecException | NoSuchAlgorithmException e ) {
55  LOGGER.info( "PubKey of " + this.name + " is not valid.", e );
56  } catch ( NumberFormatException e ) {
57  LOGGER.info( "PubKey of " + this.name + " is corrupted in database!", e );
58  }
59  }
60  return publickey;
61  }
62 
63 }
PublicKey getPubkey()
Get the public key of this organization, if known and valid.