Beispiel #1
0
  public boolean checkEncrStream(
      XStorage xParentStorage, String sName, String sMediaType, byte[] pBytes, byte[] pPass) {
    // Important: a common password for any of parent storage should not be set or
    //            should be different from pPass

    if (pPass.length == 0) {
      Error("Wrong password is used in the test!");
      return false;
    }

    try {
      xParentStorage.openStreamElement(sName, ElementModes.READ);
      Error("Encrypted stream '" + sName + "' was opened without password!");
      return false;
    } catch (WrongPasswordException wpe) {
    } catch (Exception e) {
      Error(
          "Unexpected exception in case of opening of encrypted stream '"
              + sName
              + "' without password: "******"!");
      return false;
    }

    byte pWrongPass[] = {1, 1};
    pWrongPass[0] += pPass[0];
    try {
      xParentStorage.openEncryptedStreamElement(sName, ElementModes.READ, new String(pWrongPass));
      Error("Encrypted stream '" + sName + "' was opened with wrong password!");
      return false;
    } catch (WrongPasswordException wpe) {
    } catch (Exception e) {
      Error(
          "Unexpected exception in case of opening of encrypted stream '"
              + sName
              + "' with wrong password: "******"!");
      return false;
    }

    XStream xSubStream = null;
    try {
      Object oSubStream =
          xParentStorage.openEncryptedStreamElement(sName, ElementModes.READ, new String(pPass));
      xSubStream = UnoRuntime.queryInterface(XStream.class, oSubStream);
      if (xSubStream == null) {
        Error("Can't open encrypted substream '" + sName + "'!");
        return false;
      }
    } catch (Exception e) {
      Error("Can't open encrypted substream '" + sName + "', exception : " + e + "!");
      return false;
    }

    return InternalCheckStream(xSubStream, sName, sMediaType, pBytes);
  }
Beispiel #2
0
  public boolean WriteBytesToEncrSubstream(
      XStorage xStorage,
      String sStreamName,
      String sMediaType,
      boolean bCompressed,
      byte[] pBytes,
      String sPass) {
    // open substream element
    XStream xSubStream = null;
    try {
      Object oSubStream =
          xStorage.openEncryptedStreamElement(sStreamName, ElementModes.WRITE, sPass);
      xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream);
      if (xSubStream == null) {
        Error("Can't create substream '" + sStreamName + "'!");
        return false;
      }
    } catch (Exception e) {
      Error("Can't create substream '" + sStreamName + "', exception : " + e + "!");
      return false;
    }

    if (!WriteBytesToStream(xSubStream, sStreamName, sMediaType, bCompressed, pBytes)) return false;

    // free the stream resources, garbage collector may remove the object too late
    if (!disposeStream(xSubStream, sStreamName)) return false;

    return true;
  }
Beispiel #3
0
  public int ChangeStreamPass(
      XStorage xStorage, String sStreamName, byte[] pOldPass, byte[] pNewPass) {
    // open substream element
    XStream xSubStream = null;
    try {
      Object oSubStream =
          xStorage.openEncryptedStreamElement(
              sStreamName, ElementModes.WRITE, new String(pOldPass));
      xSubStream = UnoRuntime.queryInterface(XStream.class, oSubStream);
      if (xSubStream == null) {
        Error("Can't open substream '" + sStreamName + "'!");
        return 0;
      }
    } catch (Exception e) {
      Error("Can't open substream '" + sStreamName + "', exception : " + e + "!");
      return 0;
    }

    // change the password for the stream
    XEncryptionProtectedSource xStreamEncryption =
        UnoRuntime.queryInterface(XEncryptionProtectedSource.class, xSubStream);

    if (xStreamEncryption == null) {
      Message(
          "Optional interface XEncryptionProtectedSource is not implemented, feature can not be tested!");
      return -1;
    }

    try {
      xStreamEncryption.setEncryptionPassword(new String(pNewPass));
    } catch (Exception e) {
      Error("Can't change encryption key of the substream '" + sStreamName + "', exception:" + e);
      return 0;
    }

    // free the stream resources, garbage collector may remove the object too late
    XComponent xComponent = UnoRuntime.queryInterface(XComponent.class, xSubStream);
    if (xComponent == null) {
      Error("Can't get XComponent implementation from substream '" + sStreamName + "'!");
      return 0;
    }
    xComponent.dispose();

    return 1;
  }
Beispiel #4
0
  public boolean WriteBytesToEncrSubstream(
      XStorage xStorage,
      String sStreamName,
      String sMediaType,
      boolean bCompressed,
      byte[] pBytes,
      byte[] pPass) {
    // open substream element
    XStream xSubStream = null;
    try {
      Object oSubStream =
          xStorage.openEncryptedStreamElement(sStreamName, ElementModes.WRITE, new String(pPass));
      xSubStream = UnoRuntime.queryInterface(XStream.class, oSubStream);
      if (xSubStream == null) {
        Error("Can't create substream '" + sStreamName + "'!");
        return false;
      }
    } catch (Exception e) {
      Error("Can't create substream '" + sStreamName + "', exception : " + e + "!");
      return false;
    }

    return WriteBytesToStream(xSubStream, sStreamName, sMediaType, bCompressed, pBytes);
  }
Beispiel #5
0
  public boolean checkEncrStream(
      XStorage xParentStorage, String sName, String sMediaType, byte[] pBytes, String sPass) {
    // Important: a common password for any of parent storage should not be set or
    //            should be different from sPass

    try {
      Object oSubStream = xParentStorage.openStreamElement(sName, ElementModes.READ);
      Error("Encrypted stream '" + sName + "' was opened without password!");
      return false;
    } catch (WrongPasswordException wpe) {
    } catch (Exception e) {
      Error(
          "Unexpected exception in case of opening of encrypted stream '"
              + sName
              + "' without password: "******"!");
      return false;
    }

    String sWrongPass = "******";
    sWrongPass += sPass;
    try {
      Object oSubStream =
          xParentStorage.openEncryptedStreamElement(sName, ElementModes.READ, sWrongPass);
      Error("Encrypted stream '" + sName + "' was opened with wrong password!");
      return false;
    } catch (WrongPasswordException wpe) {
    } catch (Exception e) {
      Error(
          "Unexpected exception in case of opening of encrypted stream '"
              + sName
              + "' with wrong password: "******"!");
      return false;
    }

    XStream xSubStream = null;
    try {
      Object oSubStream =
          xParentStorage.openEncryptedStreamElement(sName, ElementModes.READ, sPass);
      xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream);
      if (xSubStream == null) {
        Error("Can't open encrypted substream '" + sName + "'!");
        return false;
      }
    } catch (Exception e) {
      Error("Can't open encrypted substream '" + sName + "', exception : " + e + "!");
      return false;
    }

    // encrypted streams will be compressed always, so after the storing this property is always
    // true,
    // although before the storing it can be set to false ( it is not always clear whether a stream
    // is encrypted
    // before the storing )
    boolean bResult = InternalCheckStream(xSubStream, sName, sMediaType, true, pBytes, false);

    // free the stream resources, garbage collector may remove the object too late
    if (!disposeStream(xSubStream, sName)) return false;

    return bResult;
  }