Skip to content

Commit

Permalink
Move logging to util, deprecate all loggers
Browse files Browse the repository at this point in the history
  • Loading branch information
masomel committed Aug 19, 2016
1 parent 7e01bf9 commit 6013d8e
Show file tree
Hide file tree
Showing 25 changed files with 493 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,

// coniks-java imports
import org.coniks.crypto.Util;
import org.coniks.util.Logging;
import org.coniks.coniks_common.MsgType;
import org.coniks.coniks_common.C2SProtos.Registration;
import org.coniks.coniks_common.C2SProtos.CommitmentReq;
Expand Down Expand Up @@ -180,9 +181,7 @@ else if (opMode.equalsIgnoreCase("test")) {

// set some more configs
initEpoch = ServerConfig.getStartupTime();
MsgHandlerLogger.setup(logPath+"/msg-handler-%g");
TimerLogger.setup(logPath+"/epoch-timer-%g");
ServerLogger.setup(logPath+"/server-%g");
Logging.setup(logPath+"/server-%g", "Server");

System.setProperty("javax.net.ssl.keyStore", ServerConfig.getKeystorePath());
System.setProperty("javax.net.ssl.keyStorePassword", ServerConfig.getKeystorePassword());
Expand All @@ -198,7 +197,7 @@ else if (opMode.equalsIgnoreCase("test")) {
// check that we got a good first tree
if(initRoot == null) {
if (isFullOp) {
ServerLogger.error("An error occured while trying to build the initial tree");
Logging.error("An error occured while trying to build the initial tree");
}
else {
printStatusMsg(true, "An error occured while trying to build the initial tree");
Expand Down Expand Up @@ -231,13 +230,13 @@ else if (opMode.equalsIgnoreCase("test")) {
private static class EpochTimerTask implements Runnable {

public void run() {
TimerLogger.log("Timer task started.");
Logging.log("Timer task started.");
RootNode nextRoot = DirectoryOps.updateDirectory();

// check that we got a good first tree
if(nextRoot == null) {
if (isFullOp) {
ServerLogger.error("An error occured while trying to update the tree");
Logging.error("An error occured while trying to update the tree");
}
else {
printStatusMsg(true, "An error occured while trying to update the tree");
Expand All @@ -253,7 +252,7 @@ public void run() {

if (!ServerHistory.updateHistory(nextSTR)) {
if (isFullOp) {
ServerLogger.error("An error occured while trying to update the tree");
Logging.error("An error occured while trying to update the tree");
}
else {
printStatusMsg(true, "An error occured while trying to update the tree");
Expand All @@ -264,7 +263,7 @@ public void run() {

// we're here so the update went well
if (isFullOp) {
ServerLogger.log("Directory update successful. Next epoch: "+nextEpoch);
Logging.log("Directory update successful. Next epoch: "+nextEpoch);
}
else {
printStatusMsg(false, "Directory update successful. Next epoch: "+nextEpoch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
import java.io.IOException;

// coniks-java imports
import org.coniks.util.Convert;
import org.coniks.util.Logging;

/** Implements a logger used for debugging the CONIKS
* server.
Expand All @@ -54,7 +54,11 @@ public class DebugLogger {
/** Sets up a debug logger for the CONIKS server.
*
*@param debugLog the file name for this logger.
*
*@deprecated Replaced by
* {@link org.coniks.util.Logging#setup(String, String)}.
*/
@Deprecated
public static void setup (String debugLog) {
logger = Logger.getLogger("ConiksLogger-Debug");

Expand All @@ -65,8 +69,8 @@ public static void setup (String debugLog) {

try {
FileHandler handler = new FileHandler(debugLog,
Convert.MAX_BYTES_LOGGED_PER_FILE,
Convert.MAX_NUM_LOG_FILES, true);
Logging.MAX_BYTES_LOGGED_PER_FILE,
Logging.MAX_NUM_LOG_FILES, true);

// create a TXT formatter
SimpleFormatter fmt = new SimpleFormatter();
Expand All @@ -85,14 +89,22 @@ public static void setup (String debugLog) {

/** Writes an information message {@code msg}
* to the debug log.
*
*@deprecated Replaced by
* {@link org.coniks.util.Logging#log(String)}.
*/
@Deprecated
public static void log (String msg) {
logger.info(msg);
}

/** Writes a severe error message {@code msg}
* to the debug log.
*
*@deprecated Replaced by
* {@link org.coniks.util.Logging#error(String)}.
*/
@Deprecated
public static void error (String msg) {
logger.severe(msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,

// coniks-java imports
import org.coniks.util.Convert;
import org.coniks.util.Logging;

import org.javatuples.*;

Expand Down Expand Up @@ -129,7 +130,7 @@ public static synchronized RootNode updateDirectory() {

// this should never be the case
if(ServerHistory.getCurSTR() == null){
ServerLogger.error("Trying to update a server without a history.");
Logging.error("Trying to update a server without a history.");
return null;
}

Expand Down
63 changes: 32 additions & 31 deletions coniks_server/src/main/java/org/coniks/coniks_server/KeyChange.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
/*
Copyright (c) 2015-16, Princeton University.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Princeton University nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

Expand All @@ -38,6 +38,7 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,

// coniks-java imports
import org.coniks.crypto.*;
import org.coniks.util.Logging;

/** Implements a key change operation.
*
Expand All @@ -49,24 +50,24 @@ public class KeyChange extends Operation {
private DSAPublicKey newChangeKey;
private boolean allowsUnsignedChanges;
private boolean allowsPublicVisibility;
private byte[] sig;
private byte[] sig;
private byte[] msg;
private long counter;

/** A KeyChange object does the actual work of changing the
/** A KeyChange object does the actual work of changing the
* name-to-key mapping.
*
*@param newKeyData the new key data for the mapping
*@param newKeyData the new key data for the mapping
*@param changeKey the new change key for the mapping
*@param allowsUnsignedChanges whether the user allows unsigned mapping changes
*@param allowsPublicVisibility whether the user allows her maping to be publicly visible
*@param msg the mapping change message
*@param sig the digital signature on the mapping change message
*@param epoch the epoch during which the mapping was last changed
*@param counter the change count for the given epoch (used to order the changes)
*@param counter the change count for the given epoch (used to order the changes)
*/
public KeyChange(String newKeyData, DSAPublicKey changeKey,
boolean allowsUnsignedChanges, boolean allowsPublicVisibility,
public KeyChange(String newKeyData, DSAPublicKey changeKey,
boolean allowsUnsignedChanges, boolean allowsPublicVisibility,
byte[] msg, byte[] sig, long epoch, long counter) {
this.newKeyData = newKeyData;
this.newChangeKey = changeKey;
Expand All @@ -76,7 +77,7 @@ public KeyChange(String newKeyData, DSAPublicKey changeKey,
this.sig = sig == null ? null : Arrays.copyOf(sig, sig.length);
this.epoch = epoch;
this.counter = counter;
ServerLogger.log("Made a KC object with sig = " + Arrays.toString(this.sig));
Logging.log("Made a KC object with sig = " + Arrays.toString(this.sig));
}

/** Gets the change counter for this KeyChange operation.
Expand All @@ -87,33 +88,33 @@ public long getCounter() {
return this.counter;
}

/** Verifies whether the the mapping change is possible given the user's
/** Verifies whether the the mapping change is possible given the user's
* mapping change policy.
*
*@param uln the key directory entry for which to make the check.
*@return {@code true} if it the mapping can be changed, {@code false} otherwise
*@return {@code true} if it the mapping can be changed, {@code false} otherwise
*/
public boolean canChangeInfo(UserLeafNode uln) {
// does all the checking for changing key, but doesnt actually make changes
if (!uln.allowsUnsignedKeychange() && sig == null) {
// tried to make an unsigned change
// error
ServerLogger.error("Tried to make unsigned KeyChange but wasn't allowed");
Logging.error("Tried to make unsigned KeyChange but wasn't allowed");
return false;
}
if (!uln.allowsUnsignedKeychange()) {

boolean res = false;

try {
res = Signing.dsaVerify(uln.getChangeKey(), msg, sig);
}
catch (Exception e) {
ServerLogger.error("[KeyChange] "+e.getMessage());
Logging.error("[KeyChange] "+e.getMessage());
}

if(!res) {
ServerLogger.error("Requires that key changes be signed, but the signature was invalid");
Logging.error("Requires that key changes be signed, but the signature was invalid");
return false;
}
}
Expand All @@ -126,7 +127,7 @@ public boolean canChangeInfo(UserLeafNode uln) {
*@return {@code true} if the change succeeded, {@code false} otherwise.
*/
public boolean changeInfo(UserLeafNode uln) {
// does the actual key change
// does the actual key change
if (!canChangeInfo(uln)) {
return false;
}
Expand Down
28 changes: 15 additions & 13 deletions coniks_server/src/main/java/org/coniks/coniks_server/KeyOps.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
import java.io.PrintWriter;
import java.io.*;

// coniks-java imports
import org.coniks.coniks_common.C2SProtos.DSAPublicKeyProto;
import org.coniks.util.Logging;

/** Implements all encryption-key related operations that a
* CONIKS server must perform.
Expand Down Expand Up @@ -91,19 +93,19 @@ public static RSAPrivateKey loadSigningKey(){
return myPrivateKey;
}
catch(IOException e){
TimerLogger.error("KeyOps:loadSigningKey: Problem loading the keystore");
Logging.error("KeyOps:loadSigningKey: Problem loading the keystore");
}
catch(NoSuchAlgorithmException e){
TimerLogger.error("KeyOps:loadSigningKey: Problem with integrity check algorithm");
Logging.error("KeyOps:loadSigningKey: Problem with integrity check algorithm");
}
catch(CertificateException e){
TimerLogger.error("KeyOps:loadSigningKey: Problem with the cert(s) in keystore");
Logging.error("KeyOps:loadSigningKey: Problem with the cert(s) in keystore");
}
catch(KeyStoreException e){
TimerLogger.error("KeyOps:loadSigningKey: Problem getting Keystore instance");
Logging.error("KeyOps:loadSigningKey: Problem getting Keystore instance");
}
catch(UnrecoverableEntryException e){
TimerLogger.error("KeyOps:loadSigningKey: specified protParam were insufficient or invalid");
Logging.error("KeyOps:loadSigningKey: specified protParam were insufficient or invalid");
}
return null;
}
Expand Down Expand Up @@ -148,19 +150,19 @@ public static RSAPublicKey loadPublicKey(String keyOwner){
return publicKey;
}
catch(IOException e){
ServerLogger.error("KeyOps:loadPublicKey: Problem loading the keystore");
Logging.error("KeyOps:loadPublicKey: Problem loading the keystore");
}
catch(NoSuchAlgorithmException e){
ServerLogger.error("KeyOps:loadPublicKey: Problem with integrity check algorithm");
Logging.error("KeyOps:loadPublicKey: Problem with integrity check algorithm");
}
catch(CertificateException e){
ServerLogger.error("KeyOps:loadPublicKey: Problem with the cert(s) in keystore");
Logging.error("KeyOps:loadPublicKey: Problem with the cert(s) in keystore");
}
catch(KeyStoreException e){
ServerLogger.error("KeyOps:loadPublicKey: Problem getting Keystore instance");
Logging.error("KeyOps:loadPublicKey: Problem getting Keystore instance");
}
catch(UnrecoverableEntryException e){
ServerLogger.error("KeyOps:loadPublicKey: specified protParam were insufficient or invalid");
Logging.error("KeyOps:loadPublicKey: specified protParam were insufficient or invalid");
}
return null;
}
Expand All @@ -182,13 +184,13 @@ public static DSAPublicKey makeDSAPublicKeyFromParams(BigInteger p,
return (DSAPublicKey) keyFactory.generatePublic(publicKeySpec);
}
catch(InvalidParameterException e) {
TimerLogger.error("The given DSA key is invalid.");
Logging.error("The given DSA key is invalid.");
}
catch (InvalidKeySpecException e) {
TimerLogger.error("The given key params are invalid.");
Logging.error("The given key params are invalid.");
}
catch(NoSuchAlgorithmException e){
TimerLogger.error("DSA is invalid for some reason.");
Logging.error("DSA is invalid for some reason.");
}
return null;
}
Expand Down
Loading

0 comments on commit 6013d8e

Please sign in to comment.