Пример #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);
  }
Пример #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;
  }
Пример #3
0
  public boolean checkStream(
      XStorage xParentStorage,
      String sName,
      String sMediaType,
      boolean bCompressed,
      byte[] pBytes) {
    // open substream element first
    XStream xSubStream = null;
    try {
      Object oSubStream = xParentStorage.openStreamElement(sName, ElementModes.READ);
      xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream);
      if (xSubStream == null) {
        Error("Can't open substream '" + sName + "'!");
        return false;
      }
    } catch (Exception e) {
      Error("Can't open substream '" + sName + "', exception : " + e + "!");
      return false;
    }

    boolean bResult = InternalCheckStream(xSubStream, sName, sMediaType, bCompressed, pBytes, true);

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

    return bResult;
  }
Пример #4
0
  public boolean cantOpenStorage(XStorage xStorage, String sName) {
    // try to open an opened substorage, open call must fail
    try {
      Object oDummyStorage = xStorage.openStorageElement(sName, ElementModes.READ);
      Error("The trying to reopen opened substorage '" + sName + "' must fail!");
    } catch (Exception e) {
      return true;
    }

    return false;
  }
Пример #5
0
  public XStream cloneEncrSubStream(XStorage xStorage, String sName, String sPass) {
    // clone existing substream
    try {
      XStream xStream = xStorage.cloneEncryptedStreamElement(sName, sPass);
      return xStream;
    } catch (Exception e) {
      Error("Can't clone encrypted substream '" + sName + "', exception: " + e);
    }

    return null;
  }
Пример #6
0
  public boolean removeElement(XStorage xStorage, String sName) {
    // remove element with name sName
    try {
      xStorage.removeElement(sName);
    } catch (Exception e) {
      Error("Element removing failed, exception: " + e);
      return false;
    }

    return true;
  }
Пример #7
0
  public boolean renameElement(XStorage xStorage, String sOldName, String sNewName) {
    // rename element with name sOldName to sNewName
    try {
      xStorage.renameElement(sOldName, sNewName);
    } catch (Exception e) {
      Error("Element renaming failed, exception: " + e);
      return false;
    }

    return true;
  }
Пример #8
0
  public boolean moveElementTo(XStorage xSource, String sName, XStorage xDest) {
    // move element with name sName from xSource to xDest
    try {
      xSource.moveElementTo(sName, xDest, sName);
    } catch (Exception e) {
      Error("Element moving failed, exception: " + e);
      return false;
    }

    return true;
  }
Пример #9
0
  public boolean copyElementTo(XStorage xSource, String sName, XStorage xDest, String sTargetName) {
    // copy element with name sName from xSource to xDest
    try {
      xSource.copyElementTo(sName, xDest, sTargetName);
    } catch (Exception e) {
      Error("Element copying failed, exception: " + e);
      return false;
    }

    return true;
  }
Пример #10
0
  public boolean cantOpenStream(XStorage xStorage, String sName, int nMode) {
    // try to open the substream with specified mode must fail
    try {
      Object oDummyStream = xStorage.openStreamElement(sName, nMode);
      Error("The trying to open substream '" + sName + "' must fail!");
    } catch (Exception e) {
      return true;
    }

    return false;
  }
Пример #11
0
  public boolean copyStorage(XStorage xSourceStorage, XStorage xDestStorage) {
    // copy xSourceStorage to xDestStorage
    try {
      xSourceStorage.copyToStorage(xDestStorage);
    } catch (Exception e) {
      Error("Storage copying failed, exception: " + e);
      return false;
    }

    return true;
  }
Пример #12
0
  public XStorage openSubStorage(XStorage xStorage, String sName, int nMode) {
    // open existing substorage
    try {
      Object oSubStorage = xStorage.openStorageElement(sName, nMode);
      XStorage xSubStorage = (XStorage) UnoRuntime.queryInterface(XStorage.class, oSubStorage);
      return xSubStorage;
    } catch (Exception e) {
      Error("Can't open substorage '" + sName + "', exception: " + e);
    }

    return null;
  }
Пример #13
0
  public XStream OpenStream(XStorage xStorage, String sStreamName, int nMode) {
    // open substream element
    XStream xSubStream = null;
    try {
      Object oSubStream = xStorage.openStreamElement(sStreamName, nMode);
      xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream);
      if (xSubStream == null) Error("Can't create substream '" + sStreamName + "'!");
    } catch (Exception e) {
      Error("Can't create substream '" + sStreamName + "', exception : " + e + "!");
    }

    return xSubStream;
  }
Пример #14
0
  public XStorage cloneSubStorage(XSingleServiceFactory xFactory, XStorage xStorage, String sName) {
    // create a copy of a last committed version of specified substorage
    XStorage xResult = null;
    try {
      Object oTempStorage = xFactory.createInstance();
      xResult = (XStorage) UnoRuntime.queryInterface(XStorage.class, oTempStorage);
      if (xResult != null) xStorage.copyStorageElementLastCommitTo(sName, xResult);
    } catch (Exception e) {
      Error("Can't clone substorage '" + sName + "', exception: " + e);
      return null;
    }

    return xResult;
  }
Пример #15
0
  public boolean WBToSubstrOfEncr(
      XStorage xStorage,
      String sStreamName,
      String sMediaType,
      boolean bCompressed,
      byte[] pBytes,
      boolean bEncrypted) {
    // open substream element
    XStream xSubStream = null;
    try {
      Object oSubStream = xStorage.openStreamElement(sStreamName, ElementModes.WRITE);
      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;
    }

    // get access to the XPropertySet interface
    XPropertySet xPropSet =
        (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xSubStream);
    if (xPropSet == null) {
      Error("Can't get XPropertySet implementation from substream '" + sStreamName + "'!");
      return false;
    }

    // set properties to the stream
    try {
      xPropSet.setPropertyValue("UseCommonStoragePasswordEncryption", new Boolean(bEncrypted));
    } catch (Exception e) {
      Error(
          "Can't set 'UseCommonStoragePasswordEncryption' property to 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;
  }
Пример #16
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;
  }
Пример #17
0
  public boolean checkStream(
      XStorage xParentStorage, String sName, String sMediaType, byte[] pBytes) {
    // open substream element first
    XStream xSubStream = null;
    try {
      Object oSubStream = xParentStorage.openStreamElement(sName, ElementModes.READ);
      xSubStream = UnoRuntime.queryInterface(XStream.class, oSubStream);
      if (xSubStream == null) {
        Error("Can't open substream '" + sName + "'!");
        return false;
      }
    } catch (Exception e) {
      Error("Can't open substream '" + sName + "', exception : " + e + "!");
      return false;
    }

    return InternalCheckStream(xSubStream, sName, sMediaType, pBytes);
  }
Пример #18
0
  public boolean WriteBytesToSubstream(
      XStorage xStorage,
      String sStreamName,
      String sMediaType,
      boolean bCompressed,
      byte[] pBytes) {
    // open substream element
    XStream xSubStream = null;
    try {
      Object oSubStream = xStorage.openStreamElement(sStreamName, ElementModes.WRITE);
      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);
  }
Пример #19
0
  public boolean WBToSubstrOfEncr(
      XStorage xStorage,
      String sStreamName,
      String sMediaType,
      boolean bCompressed,
      byte[] pBytes,
      boolean bEncrypted) {
    // open substream element
    XStream xSubStream = null;
    try {
      Object oSubStream = xStorage.openStreamElement(sStreamName, ElementModes.WRITE);
      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;
    }

    // get access to the XPropertySet interface
    XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xSubStream);
    if (xPropSet == null) {
      Error("Can't get XPropertySet implementation from substream '" + sStreamName + "'!");
      return false;
    }

    // set properties to the stream
    try {
      xPropSet.setPropertyValue("Encrypted", Boolean.valueOf(bEncrypted));
    } catch (Exception e) {
      Error("Can't set 'Encrypted' property to substream '" + sStreamName + "', exception: " + e);
      return false;
    }

    return WriteBytesToStream(xSubStream, sStreamName, sMediaType, bCompressed, pBytes);
  }
Пример #20
0
  public boolean WriteBytesToSubstreamDefaultCompressed(
      XStorage xStorage, String sStreamName, String sMediaType, byte[] pBytes) {
    // open substream element
    XStream xSubStream = null;
    try {
      Object oSubStream = xStorage.openStreamElement(sStreamName, ElementModes.WRITE);
      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;
    }

    // get output stream of substream
    XOutputStream xOutput = xSubStream.getOutputStream();
    if (xOutput == null) {
      Error("Can't get XOutputStream implementation from substream '" + sStreamName + "'!");
      return false;
    }

    // get XTrucate implementation from output stream
    XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface(XTruncate.class, xOutput);
    if (xTruncate == null) {
      Error("Can't get XTruncate implementation from substream '" + sStreamName + "'!");
      return false;
    }

    // write requested byte sequence
    try {
      xTruncate.truncate();
      xOutput.writeBytes(pBytes);
    } catch (Exception e) {
      Error("Can't write to stream '" + sStreamName + "', exception: " + e);
      return false;
    }

    // get access to the XPropertySet interface
    XPropertySet xPropSet =
        (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xSubStream);
    if (xPropSet == null) {
      Error("Can't get XPropertySet implementation from substream '" + sStreamName + "'!");
      return false;
    }

    // set properties to the stream
    // do not set the compressed property
    try {
      xPropSet.setPropertyValue("MediaType", sMediaType);
    } catch (Exception e) {
      Error("Can't set properties to substream '" + sStreamName + "', exception: " + e);
      return false;
    }

    // check size property of the stream
    try {
      long nSize = AnyConverter.toLong(xPropSet.getPropertyValue("Size"));
      if (nSize != pBytes.length) {
        Error("The 'Size' property of substream '" + sStreamName + "' contains wrong value!");
        return false;
      }
    } catch (Exception e) {
      Error("Can't get 'Size' property from substream '" + sStreamName + "', exception: " + e);
      return false;
    }

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

    return true;
  }
Пример #21
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;
  }