pax_global_header00006660000000000000000000000064127563430450014523gustar00rootroot0000000000000052 comment=532aea5c5a8e20c6d7c0a1aa43bd07cd6af38e8f sdes4j-1.1.4/000077500000000000000000000000001275634304500127225ustar00rootroot00000000000000sdes4j-1.1.4/.gitignore000066400000000000000000000001271275634304500147120ustar00rootroot00000000000000.classpath .project .settings bin build coverage publish.properties target *.iml .idea sdes4j-1.1.4/LICENSE000066400000000000000000000576351275634304500137470ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONSsdes4j-1.1.4/README.md000066400000000000000000000010311275634304500141740ustar00rootroot00000000000000sdes4j ====== Implementation of RFC4568: Session Description Protocol (SDP) Security Descriptions for Media Streams for Java. Build ----- Run `mvn package` Projects using sdes4j --------------------- [Jitsi](https://jitsi.org), the open source VoIP and Instant Messaging Client. Downloads --------- Binaries are available from [Google Drive](https://drive.google.com/folderview?id=0BwiF7kZbHitaa2JkV1RrOWk0blk&usp=sharing) or on [Maven Central](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22ch.imvs%22%20AND%20a%3A%22sdes4j%22). sdes4j-1.1.4/pom.xml000066400000000000000000000102561275634304500142430ustar00rootroot00000000000000 4.0.0 ch.imvs sdes4j 1.1.4 bundle sdes4j SDES (RFC4568) implementation for Java http://github.com/ibauersachs/sdes4j University of Applied Sciences Northwestern Switzerland GNU Lesser General Public License, Version 2.1 http://www.gnu.org/licenses/lgpl-2.1.txt repo scm:git:https://github.com/ibauersachs/sdes4j.git https://github.com/ibauersachs/sdes4j r1.1.4 ibauersachs Ingo Bauersachs ibauersachs@gmail.com UTF-8 commons-codec commons-codec [1.4,2.0) compile junit junit 4.11 test maven-compiler-plugin 3.5.1 1.7 1.7 org.apache.felix maven-bundle-plugin 3.2.0 true maven-surefire-plugin 2.14 org.apache.maven.plugins maven-release-plugin 2.5.3 release performRelease true org.apache.maven.plugins maven-source-plugin 3.0.1 attach-sources jar-no-fork org.apache.maven.plugins maven-javadoc-plugin 2.10.4 attach-javadocs jar org.apache.maven.plugins maven-gpg-plugin 1.6 sign-artifacts verify sign org.sonatype.plugins nexus-staging-maven-plugin 1.6.7 true ossrh https://oss.sonatype.org/ false ossrh https://oss.sonatype.org/content/repositories/snapshots ossrh https://oss.sonatype.org/service/local/staging/deploy/maven2/ sdes4j-1.1.4/src/000077500000000000000000000000001275634304500135115ustar00rootroot00000000000000sdes4j-1.1.4/src/main/000077500000000000000000000000001275634304500144355ustar00rootroot00000000000000sdes4j-1.1.4/src/main/java/000077500000000000000000000000001275634304500153565ustar00rootroot00000000000000sdes4j-1.1.4/src/main/java/ch/000077500000000000000000000000001275634304500157505ustar00rootroot00000000000000sdes4j-1.1.4/src/main/java/ch/imvs/000077500000000000000000000000001275634304500167265ustar00rootroot00000000000000sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/000077500000000000000000000000001275634304500201225ustar00rootroot00000000000000sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/CryptoAttribute.java000066400000000000000000000230211275634304500241270ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j; import java.util.*; /** * Primary class for a RFC4568 Crypto Attribute. * * @author Ingo Bauersachs */ public class CryptoAttribute { protected int tag; protected CryptoSuite cryptoSuite; protected KeyParam[] keyParams; protected SessionParam[] sessionParams = null; protected CryptoAttribute(){ } /** * Creates an instance of a CryptoAttribute from an SDes string in the * format of * tag 1*WSP crypto-suite 1*WSP key-params *(1*WSP session-param) * * @param attribute the encoded SDes attribute * @param f factory that creates the instances for each part of the * attribute * @return a parsed crypto attribute */ public static CryptoAttribute create(String attribute, SDesFactory f) { CryptoAttribute result = f.createCryptoAttribute(); List tokens = new LinkedList(); for (String s : attribute.split("\\s")){ if(s.trim().length() > 0) tokens.add(s); } result.setTag(tokens.remove(0)); result.setCryptoSuite(tokens.remove(0), f); if (tokens.size() < 1) throw new IllegalArgumentException("There must be at least one key parameter"); result.setKeyParams(tokens.remove(0), f); result.setSessionParams(tokens, f); return result; } /** * Creates an instance of a CryptoAttribute from a SDes attributes (tag, * crypto suite, key params and session params). * * @param tag unparsed tag as a string. * @param cryptoSuite the crypto suite as an unparsed string. * @param keyParams An unparsed string representation of the key param list * (each key must be separated by a ";"). * @param sessionParams An unparsed string representation of the session * param list (each key must be separated by a " "). * @param f factory that creates the instances for each part of the * attribute * * @return a parsed crypto attribute */ public static CryptoAttribute create(String tag, String cryptoSuite, String keyParams, String sessionParams, SDesFactory f) { CryptoAttribute result = f.createCryptoAttribute(); result.setTag(tag); result.setCryptoSuite(cryptoSuite, f); result.setKeyParams(keyParams, f); List tokens = new LinkedList(); if(sessionParams != null) { for (String s : sessionParams.split("\\s")) { if(s.trim().length() > 0) tokens.add(s); } } result.setSessionParams(tokens, f); return result; } /** * Creates a crypto attribute from already instantiated objects. * * @param tag identifier for this particular crypto attribute * @param cryptoSuite identifier that describes the encryption and * authentication algorithms * @param keyParams one or more sets of keying material * @param sessionParams the additional key parameters */ public CryptoAttribute(int tag, CryptoSuite cryptoSuite, KeyParam[] keyParams, SessionParam[] sessionParams) { if (tag > 99999999 || tag < 0) throw new IllegalArgumentException("tag can have at most 10 digits and must be non-negative"); if (cryptoSuite == null) throw new IllegalArgumentException("cryptoSuite cannot be null"); if (keyParams == null || keyParams.length == 0) throw new IllegalArgumentException("keyParams cannot be null or empty"); this.tag = tag; this.cryptoSuite = cryptoSuite; this.keyParams = keyParams; if (sessionParams == null) this.sessionParams = new SessionParam[0]; else this.sessionParams = sessionParams; } /** * Gets the identifier for this particular crypto attribute. * * @return the tag */ public int getTag() { return tag; } /** * Sets the tag which is used as an identifier for this particular crypto * attribute. The tag MUST be unique among all crypto attributes for a given * media line. * * @param stringTag unparsed tag as a string. */ private void setTag(String stringTag) { int tag = Integer.valueOf(stringTag); if (tag > 99999999 || tag < 0) throw new IllegalArgumentException("tag can have at most 10 digits and must be non-negative"); this.tag = tag; } /** * Gets the identifier that describes the encryption and authentication * algorithms (e.g., AES_CM_128_HMAC_SHA1_80) for the transport in question. * * @return the cryptoSuite */ public CryptoSuite getCryptoSuite() { return cryptoSuite; } /** * Sets the identifier that describes the encryption and authentication * algorithms (e.g., AES_CM_128_HMAC_SHA1_80) for the transport in question. * * @param stringCryptoSuite the crypto suite as an unparsed string. * @param f factory that creates the crypto suite instance */ private void setCryptoSuite(String stringCryptoSuite, SDesFactory f) { this.cryptoSuite = f.createCryptoSuite(stringCryptoSuite); } /** * Gets one or more sets of keying material for the crypto-suite in * question. * * @return the keyParams */ public KeyParam[] getKeyParams() { return keyParams; } /** * Sets one or more sets of keying material for the crypto-suite in * question. * * @param stringKeyParams An unparsed string representation of the key param * list (each key must be separated by a ";"). * @param f factory that creates the key params instances */ private void setKeyParams(String stringKeyParams, SDesFactory f) { String[] params = stringKeyParams.split(";"); List keyParams = new LinkedList(); for (String p : params) { keyParams.add(f.createKeyParam(p)); } this.keyParams = keyParams.toArray(f.createKeyParamArray(0)); } /** * Gets the additional key parameters for this particular crypto attribute. * * @return the sessionParams */ public SessionParam[] getSessionParams() { return sessionParams; } /** * Sets additional key parameters for this particular crypto attribute. * * @param tokens List of String-Tokens where the matching items are consumed * and removed from the list * @param f factory that creates the session params instances */ private void setSessionParams(List tokens, SDesFactory f) { List sessionParams = new LinkedList(); while (tokens.size() > 0) { sessionParams.add(f.createSessionParam(tokens.remove(0))); } this.sessionParams = sessionParams.toArray(f.createSessionParamArray(0)); } /** * Encodes this crypto attribute as a string according to the ABNF rule * tag 1*WSP crypto-suite 1*WSP key-params *(1*WSP session-param) * * @return Complete crypto attribute for use in the SDP. */ public String encode() { StringBuilder sb = new StringBuilder(); sb.append(tag); sb.append(' '); sb.append(cryptoSuite.encode()); sb.append(' '); sb.append(getKeyParamsString()); if (sessionParams != null && sessionParams.length > 0) { sb.append(' '); sb.append(getSessionParamsString()); } return sb.toString(); } /** * Returns a string representation the key parameters according to the ABNF * rule key-params. * * @return String representation of the list of key params separated by ";". */ public String getKeyParamsString() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < keyParams.length; i++) { sb.append(keyParams[i].encode()); if (i < keyParams.length - 1) sb.append(';'); } return sb.toString(); } /** * Returns a string representation of the session parameters according to * the ABNF rule session-param. * * @return Returns a string representation of the list of session params * separated by " ", or null if there are no session params. */ public String getSessionParamsString() { if (sessionParams != null && sessionParams.length > 0) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < sessionParams.length; i++) { sb.append(sessionParams[i].encode()); if (i < sessionParams.length - 1) sb.append(' '); } return sb.toString(); } else{ return null; } } @Override public boolean equals(Object obj) { if (obj != null && obj instanceof CryptoAttribute) { CryptoAttribute other = (CryptoAttribute)obj; return encode().equals(other.encode()); } return false; } @Override public int hashCode() { return encode().hashCode(); } } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/CryptoSuite.java000066400000000000000000000015411275634304500232600ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j; /** * Interface for grammar implementations of an identifier that describes the * encryption and authentication algorithms (e.g., AES_CM_128_HMAC_SHA1_80) for * the transport in question * * @author Ingo Bauersachs */ public interface CryptoSuite { /** * Encodes the information contained in this object for use in the complete * crypto attribute. * * @return The name of the crypto suite. */ String encode(); } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/KeyParam.java000066400000000000000000000021631275634304500225000ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j; /** * The key-param provides keying material for the crypto-suite in question. It * consists of a method and the actual keying information * * @author Ingo Bauersachs */ public interface KeyParam { /** * Gets the method name that defines the type of the key information. Only * one method is defined, namely, "inline", which indicates that the actual * keying material is provided in the key-info field itself. * * @return inline */ String getKeyMethod(); /** * Encodes the information contained in this object for use in the complete * crypto attribute. * * @return Textual representation of the key parameter. */ String encode(); } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/SDesFactory.java000066400000000000000000000045041275634304500231560ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j; import java.util.Random; /** * Interface to create instances of specific grammar * * @author Ingo Bauersachs */ public interface SDesFactory { /** * Creates a crypto suite instance for the grammar implementing this interface. * * @param suite The suite name that defines the cryptographic parameters. * @return A crypto suite instance based on the supplied suite name. */ CryptoSuite createCryptoSuite(String suite); /** * Creates a key parameter instance for the grammar implementing this interface. * * @param keyParam The textual representation of the key parameter field. * @return The parsed key parameter. */ KeyParam createKeyParam(String keyParam); /** * Utility method to create a typed array of KeyParameters. * * @param size The size of the array to create. * @return KeyParam array of the specified size. */ KeyParam[] createKeyParamArray(int size); /** * Creates a session parameter instance for the grammar implementing this interface. * * @param sessionParam The textual representation of the session parameter. * @return The parsed session parameter. */ SessionParam createSessionParam(String sessionParam); /** * Utility method to create a typed array of SessionParams. * * @param size The size of the array to create. * @return SessionParam array of the specified size. */ SessionParam[] createSessionParamArray(int size); /** * Creates an empty crypto attribute for the grammar implementing this interface. * * @return Empty crypto attribute to be filled by a parser. */ CryptoAttribute createCryptoAttribute(); /** * Sets the random number generator to be used for generating the SDES keys. * * @param r The random number generator. */ void setRandomGenerator(Random r); } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/SessionParam.java000066400000000000000000000014071275634304500233730ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j; /** * Interface for Session parameters that are specific to a given transport. * * @author Ingo Bauersachs */ public interface SessionParam { /** * Encodes the information contained in this object for use in the complete * crypto attribute. * * @return Textual representation of the session parameter. */ String encode(); } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/000077500000000000000000000000001275634304500211125ustar00rootroot00000000000000sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/FecKeySessionParam.java000066400000000000000000000043201275634304500254470ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; /** * FEC_KEY signals the use of separate master key(s) for a Forward Error * Correction (FEC) stream. * * @author Ingo Bauersachs */ public class FecKeySessionParam extends SrtpSessionParam { private SrtpKeyParam[] keyParams; /** * Creates a new instance of this class from known key parameters. * @param keyParams The key parameters to use for this FEC session parameter. */ public FecKeySessionParam(SrtpKeyParam[] keyParams) { this.keyParams = keyParams; } /** * Creates a new instance of this class from the textual representation of the session parameter. * @param param The textual representation of the session parameter. */ public FecKeySessionParam(String param) { String[] params = param.substring("FEC_KEY=".length()).split(";"); this.keyParams = new SrtpKeyParam[params.length]; for (int i = 0; i < this.keyParams.length; i++) { this.keyParams[i] = createSrtpKeyParam(params[i]); } } /** * Factory method to create the key parameter objects. * * @param p The key parameter to parse. * @return The parsed key parameter. */ protected SrtpKeyParam createSrtpKeyParam(String p) { return new SrtpKeyParam(p); } /** * Gets the key parameters of this session parameter. * @return The key parameters of this session parameter. */ public SrtpKeyParam[] getKeyParams() { return keyParams; } @Override public String encode() { StringBuilder sb = new StringBuilder(); sb.append("FEC_KEY="); for (int i = 0; i < keyParams.length; i++) { sb.append(keyParams[i].encode()); if (i < keyParams.length - 1) sb.append(';'); } return sb.toString(); } } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/FecOrderSessionParam.java000066400000000000000000000053701275634304500260000ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; /** * FEC_ORDER signals the use of forward error correction for the RTP packets * [RFC2733]. The forward error correction values for "order" are FEC_SRTP or * SRTP_FEC. FEC_SRTP signals that FEC is applied before SRTP processing by the * sender of the SRTP media and after SRTP processing by the receiver of the * SRTP media; FEC_SRTP is the default. SRTP_FEC is the reverse processing. * * @author Ingo Bauersachs */ public class FecOrderSessionParam extends SrtpSessionParam { /** * FEC_SRTP signals that FEC is applied before SRTP processing by the sender * of the SRTP media and after SRTP processing by the receiver of the SRTP * media; FEC_SRTP is the default. */ public final static int FEC_SRTP = 1; /** * SRTP_FEC signals that SRTP processing is performed before applying FEC by * the sender of the SRTP media and after FEC processing by the receiver of * the SRTP media. */ public final static int SRTP_FEC = 2; private int mode; /** * Creates a new instance of this class from a known order value. * * @param mode {@value #FEC_SRTP} or {@value #SRTP_FEC} */ public FecOrderSessionParam(int mode) { if (mode != FEC_SRTP && mode != SRTP_FEC) throw new IllegalArgumentException("mode must be one of FEC_SRTP or SRTP_FEC"); this.mode = mode; } /** * Creates a new instance of this class from the textual representation of * the session parameter. * * @param param The textual representation of the session parameter. */ public FecOrderSessionParam(String param) { param = param.substring("FEC_ORDER=".length()); if (param.equals("FEC_SRTP")) mode = FEC_SRTP; else if (param.equals("SRTP_FEC")) mode = SRTP_FEC; else throw new IllegalArgumentException("unknown value"); } /** * Gets the forward error correction mode. * * @return {@value #SRTP_FEC} or {@value #FEC_SRTP} */ public int getMode() { return mode; } @Override public String encode() { switch (mode) { case FEC_SRTP: return "FEC_ORDER=FEC_SRTP"; case SRTP_FEC: return "FEC_ORDER=SRTP_FEC"; } throw new IllegalArgumentException("invalid mode"); } } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/KdrSessionParam.java000066400000000000000000000045141275634304500250260ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; /** * KDR specifies the Key Derivation Rate, as described in Section 4.3.1 of * [RFC3711]. * * The value n MUST be a decimal integer in the set {1,2,...,24}, which denotes * a power of 2 from 2^1 to 2^24, inclusive; leading zeroes MUST NOT be used. * The SRTP key derivation rate controls how frequently a new session key is * derived from an SRTP master key(s) [RFC3711] given in the declaration. When * the key derivation rate is not specified (i.e., the KDR parameter is * omitted), a single initial key derivation is performed [RFC3711]. * * @author Ingo Bauersachs */ public class KdrSessionParam extends SrtpSessionParam { private int kdr; /** * Creates a new instance of this class from a known derivation rate. * * @param kdr The key derivation rate. */ public KdrSessionParam(int kdr) { if (kdr < 0 || kdr > 24) throw new IllegalArgumentException("kdr must be in range 0..24 inclusive"); this.kdr = kdr; } /** * Creates a new instance of this class from the textual representation. * * @param param The textual representation of the key derivation rate parameter. */ public KdrSessionParam(String param) { kdr = Integer.valueOf(param.substring("KDR=".length())); if (kdr < 0 || kdr > 24) throw new IllegalArgumentException("kdr must be in range 0..24 inclusive"); } /** * The key derivation rate as encoded in the session parameters. * * @return decimal integer in the set {1,2,...,24} */ public int getKeyDerivationRate() { return kdr; } /** * The key derivation rate in its exponentiated form. * * @return integer in the range from 2 to 16'777'216. */ public int getKeyDerivationRateExpanded() { return (int) Math.pow(2, kdr); } @Override public String encode() { return "KDR=" + String.valueOf(kdr); } } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/NoAuthSessionParam.java000066400000000000000000000021561275634304500255040ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; /** * SRTP and SRTCP packet payloads are authenticated by default. The * UNAUTHENTICATED_SRTP session parameter signals that SRTP messages are not * authenticated. Use of UNAUTHENTICATED_SRTP is NOT RECOMMENDED (see Security * Considerations). * * @author Ingo Bauersachs */ public class NoAuthSessionParam extends SrtpSessionParam { private static final String UNAUTHENTICATED_SRTP = "UNAUTHENTICATED_SRTP"; @Override public String encode() { return UNAUTHENTICATED_SRTP; } @Override public int hashCode() { return UNAUTHENTICATED_SRTP.hashCode(); } @Override public boolean equals(Object obj) { return UNAUTHENTICATED_SRTP.equals(obj); } } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/PlainSrtcpSessionParam.java000066400000000000000000000022141275634304500263600ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; /** * SRTP and SRTCP packet payloads are encrypted by default. The * UNENCRYPTED_SRTCP and UNENCRYPTED_SRTP session parameters modify the default * behavior of the crypto-suites with which they are used. * * UNENCRYPTED_SRTCP signals that the SRTP packet payloads are not encrypted. * * @author Ingo Bauersachs */ public class PlainSrtcpSessionParam extends SrtpSessionParam { private static final String UNENCRYPTED_SRTCP = "UNENCRYPTED_SRTCP"; @Override public String encode() { return UNENCRYPTED_SRTCP; } @Override public int hashCode() { return UNENCRYPTED_SRTCP.hashCode(); } @Override public boolean equals(Object obj) { return UNENCRYPTED_SRTCP.equals(obj); } } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/PlainSrtpSessionParam.java000066400000000000000000000022051275634304500262150ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; /** * SRTP and SRTCP packet payloads are encrypted by default. The * UNENCRYPTED_SRTCP and UNENCRYPTED_SRTP session parameters modify the default * behavior of the crypto-suites with which they are used. * * UNENCRYPTED_SRTP signals that the SRTP packet payloads are not encrypted. * * @author Ingo Bauersachs */ public class PlainSrtpSessionParam extends SrtpSessionParam { private static final String UNENCRYPTED_SRTP = "UNENCRYPTED_SRTP"; @Override public String encode() { return UNENCRYPTED_SRTP; } @Override public int hashCode() { return UNENCRYPTED_SRTP.hashCode(); } @Override public boolean equals(Object obj) { return UNENCRYPTED_SRTP.equals(obj); } } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/SrtpCryptoAttribute.java000066400000000000000000000046521275634304500260010ustar00rootroot00000000000000package ch.imvs.sdes4j.srtp; import ch.imvs.sdes4j.CryptoAttribute; /** * Security descriptions attribute for SRTP media streams. * * @author Ingo Bauersachs */ public class SrtpCryptoAttribute extends CryptoAttribute { SrtpCryptoAttribute(){ } /** * Creates an SRTP crypto attribute from its textual representation. * * @param encoded The textual representation of the attribute. * @return The parsed crypto data. */ public static SrtpCryptoAttribute create(String encoded){ return (SrtpCryptoAttribute)CryptoAttribute.create(encoded, new SrtpSDesFactory()); } /** * Creates an instance of a SrtpCryptoAttribute from SDES attributes (tag, * crypto suite, key params and session params). * * @param tag unparsed tag as a string. * @param cryptoSuite the crypto suite as an unparsed string. * @param keyParams An unparsed string representation of the key param list * (each key must be separated by a ";"). * @param sessionParams An unparsed string representation of the session * param list (each key must be separated by a " "). * * @return a parsed SRTP crypto attribute. */ public static SrtpCryptoAttribute create(String tag, String cryptoSuite, String keyParams, String sessionParams){ return (SrtpCryptoAttribute) CryptoAttribute.create(tag, cryptoSuite, keyParams, sessionParams, new SrtpSDesFactory()); } /** * Creates a crypto attribute from already instantiated objects. * * @param tag identifier for this particular crypto attribute * @param cryptoSuite identifier that describes the encryption and * authentication algorithms * @param keyParams one or more sets of keying material * @param sessionParams the additional key parameters */ public SrtpCryptoAttribute(int tag, SrtpCryptoSuite cryptoSuite, SrtpKeyParam[] keyParams, SrtpSessionParam[] sessionParams) { super(tag, cryptoSuite, keyParams, sessionParams == null ? new SrtpSessionParam[0] : sessionParams); } @Override public SrtpCryptoSuite getCryptoSuite() { return (SrtpCryptoSuite) super.getCryptoSuite(); } @Override public SrtpKeyParam[] getKeyParams() { return (SrtpKeyParam[]) super.getKeyParams(); } @Override public SrtpSessionParam[] getSessionParams() { return (SrtpSessionParam[]) super.getSessionParams(); } } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/SrtpCryptoSuite.java000066400000000000000000000207431275634304500251260ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import ch.imvs.sdes4j.CryptoSuite; /** * Crypto suite details for the SRTP grammar. * * @author Ingo Bauersachs */ public class SrtpCryptoSuite implements CryptoSuite { public static final String AES_256_CM_HMAC_SHA1_32 = "AES_256_CM_HMAC_SHA1_32"; public static final String AES_256_CM_HMAC_SHA1_80 = "AES_256_CM_HMAC_SHA1_80"; public static final String AES_192_CM_HMAC_SHA1_32 = "AES_192_CM_HMAC_SHA1_32"; public static final String AES_192_CM_HMAC_SHA1_80 = "AES_192_CM_HMAC_SHA1_80"; public static final String SEED_128_GCM_96 = "SEED_128_GCM_96"; public static final String SEED_128_CCM_80 = "SEED_128_CCM_80"; public static final String SEED_CTR_128_HMAC_SHA1_80 = "SEED_CTR_128_HMAC_SHA1_80"; public static final String F8_128_HMAC_SHA1_80 = "F8_128_HMAC_SHA1_80"; public static final String AES_CM_128_HMAC_SHA1_32 = "AES_CM_128_HMAC_SHA1_32"; public static final String AES_CM_128_HMAC_SHA1_80 = "AES_CM_128_HMAC_SHA1_80"; public final static int ENCRYPTION_AES128_CM = 1; public final static int ENCRYPTION_AES128_F8 = 2; public final static int ENCRYPTION_SEED128_CTR = 5; public final static int ENCRYPTION_SEED128_CCM_80 = 6; public final static int ENCRYPTION_SEED128_GCM_96 = 7; public final static int ENCRYPTION_AES192_CM = 8; public final static int ENCRYPTION_AES256_CM = 9; public final static int HASH_HMAC_SHA1 = 1; public final static int HASH_SEED128_CCM_80 = 3; public final static int HASH_SEED128_GCM_96 = 4; private final String suite; private int encryptionAlgorithm; private int hashAlgoritm; private int encKeyLength; private int saltKeyLength; private int srtpAuthTagLength; private int srtcpAuthTagLength; private int srtpAuthKeyLength; private int srtcpAuthKeyLength; private long srtpLifetime; private long srtcpLifetime; public SrtpCryptoSuite(String suite) { this.suite = suite; // as per http://www.iana.org/assignments/sdp-security-descriptions if (suite.equals(AES_CM_128_HMAC_SHA1_80)) { encryptionAlgorithm = ENCRYPTION_AES128_CM; hashAlgoritm = HASH_HMAC_SHA1; encKeyLength = 128; saltKeyLength = 112; srtpAuthTagLength = 80; srtcpAuthTagLength = 80; srtpAuthKeyLength = 160; srtcpAuthKeyLength = 160; srtpLifetime = 0x1000000000000L; srtcpLifetime = 0x80000000L; } else if (suite.equals(AES_CM_128_HMAC_SHA1_32)) { encryptionAlgorithm = ENCRYPTION_AES128_CM; hashAlgoritm = HASH_HMAC_SHA1; encKeyLength = 128; saltKeyLength = 112; srtpAuthTagLength = 32; srtcpAuthTagLength = 80; srtpAuthKeyLength = 160; srtcpAuthKeyLength = 160; srtpLifetime = 0x1000000000000L; srtcpLifetime = 0x80000000L; } else if (suite.equals(F8_128_HMAC_SHA1_80)) { encryptionAlgorithm = ENCRYPTION_AES128_F8; hashAlgoritm = HASH_HMAC_SHA1; encKeyLength = 128; saltKeyLength = 112; srtpAuthTagLength = 80; srtcpAuthTagLength = 80; srtpAuthKeyLength = 160; srtcpAuthKeyLength = 160; srtpLifetime = 0x1000000000000L; srtcpLifetime = 0x80000000L; } // FIXME all that SEED stuff is not precisely declared in RFC5669 else if (suite.equals(SEED_CTR_128_HMAC_SHA1_80)) { encryptionAlgorithm = ENCRYPTION_SEED128_CTR; hashAlgoritm = HASH_HMAC_SHA1; encKeyLength = 128; saltKeyLength = 128; srtpAuthTagLength = 80; srtcpAuthTagLength = 80; srtpAuthKeyLength = -1; srtcpAuthKeyLength = -1; srtpLifetime = 0x1000000000000L; srtcpLifetime = 0x80000000L; throw new UnsupportedOperationException("SEED parameters are not known for sure"); } else if (suite.equals(SEED_128_CCM_80)) { encryptionAlgorithm = ENCRYPTION_SEED128_CCM_80; hashAlgoritm = HASH_SEED128_CCM_80; encKeyLength = 128; saltKeyLength = 128; srtpAuthTagLength = 80; srtcpAuthTagLength = 80; srtpAuthKeyLength = -1; srtcpAuthKeyLength = -1; srtpLifetime = 0x1000000000000L; srtcpLifetime = 0x80000000L; throw new UnsupportedOperationException("SEED parameters are not known for sure"); } else if (suite.equals(SEED_128_GCM_96)) { encryptionAlgorithm = ENCRYPTION_SEED128_GCM_96; hashAlgoritm = HASH_SEED128_GCM_96; encKeyLength = 128; saltKeyLength = 128; srtpAuthTagLength = 96; srtcpAuthTagLength = 96; srtpAuthKeyLength = -1; srtcpAuthKeyLength = -1; srtpLifetime = 0x1000000000000L; srtcpLifetime = 0x80000000L; throw new UnsupportedOperationException("SEED parameters are not known for sure"); } else if (suite.equals(AES_192_CM_HMAC_SHA1_80)) { encryptionAlgorithm = ENCRYPTION_AES192_CM; hashAlgoritm = HASH_HMAC_SHA1; encKeyLength = 192; saltKeyLength = 112; srtpAuthTagLength = 80; srtcpAuthTagLength = 80; srtpAuthKeyLength = 160; srtcpAuthKeyLength = 160; srtpLifetime = 0x80000000L; srtcpLifetime = 0x80000000L; } else if (suite.equals(AES_192_CM_HMAC_SHA1_32)) { encryptionAlgorithm = ENCRYPTION_AES192_CM; hashAlgoritm = HASH_HMAC_SHA1; encKeyLength = 192; saltKeyLength = 112; srtpAuthTagLength = 32; srtcpAuthTagLength = 80; srtpAuthKeyLength = 160; srtcpAuthKeyLength = 160; srtpLifetime = 0x80000000L; srtcpLifetime = 0x80000000L; } else if (suite.equals(AES_256_CM_HMAC_SHA1_80)) { encryptionAlgorithm = ENCRYPTION_AES256_CM; hashAlgoritm = HASH_HMAC_SHA1; encKeyLength = 256; saltKeyLength = 112; srtpAuthTagLength = 80; srtcpAuthTagLength = 80; srtpAuthKeyLength = 160; srtcpAuthKeyLength = 160; srtpLifetime = 0x80000000L; srtcpLifetime = 0x80000000L; } else if (suite.equals(AES_256_CM_HMAC_SHA1_32)) { encryptionAlgorithm = ENCRYPTION_AES256_CM; hashAlgoritm = HASH_HMAC_SHA1; encKeyLength = 256; saltKeyLength = 112; srtpAuthTagLength = 32; srtcpAuthTagLength = 80; srtpAuthKeyLength = 160; srtcpAuthKeyLength = 160; srtpLifetime = 0x80000000L; srtcpLifetime = 0x80000000L; } else throw new IllegalArgumentException("Unknown crypto suite"); } public int getEncryptionAlgorithm() { return encryptionAlgorithm; } public int getHashAlgorithm() { return hashAlgoritm; } public int getEncKeyLength() { return encKeyLength; } public int getSaltKeyLength() { return saltKeyLength; } public int getSrtpAuthTagLength() { return srtpAuthTagLength; } public int getSrtcpAuthTagLength() { return srtcpAuthTagLength; } public int getSrtpAuthKeyLength() { return srtpAuthKeyLength; } public int getSrtcpAuthKeyLength() { return srtcpAuthKeyLength; } public long getSrtpLifetime() { return srtpLifetime; } public long getSrtcpLifetime() { return srtcpLifetime; } @Override public String encode() { return suite; } @Override public boolean equals(Object obj) { if(obj instanceof SrtpCryptoSuite && obj != null) return suite.equals(((SrtpCryptoSuite)obj).suite); return false; } @Override public int hashCode() { return suite.hashCode(); } } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/SrtpKeyParam.java000066400000000000000000000125731275634304500243470ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.StringUtils; import ch.imvs.sdes4j.KeyParam; /** * SRTP security descriptions define the use of the "inline" key method. Use of * any other keying method (e.g., URL) for SRTP security descriptions is for * further study. * * The "inline" type of key contains the keying material (master key and salt) * and all policy related to that master key, including how long it can be used * (lifetime) and whether it uses a master key identifier (MKI) to associate an * incoming SRTP packet with a particular master key. * * @author Ingo Bauersachs * */ public class SrtpKeyParam implements KeyParam { /** * Constant for the inline key method. */ public final static String KEYMETHOD_INLINE = "inline"; private final String keyMethod = KEYMETHOD_INLINE; private byte[] key; private int lifetime; private int mki; private int mkiLength; /** * Creates a new instance of this class from known parameters. * * @param keyMethod The key method for this key parameter. Only * {@value #KEYMETHOD_INLINE} is currently supported. * @param key Concatenated master key and salt; MUST be a unique * cryptographically random value with respect to other master * keys in the entire SDP message (i.e., including master keys * for other streams) * @param lifetime The master key lifetime (max number of SRTP or SRTCP packets * using this master key) * @param mki The master key identifier in the SRTP packets. * @param mkiLength Length of the MKI field in SRTP packets. */ public SrtpKeyParam(String keyMethod, byte[] key, int lifetime, int mki, int mkiLength) { if (!keyMethod.equals(KEYMETHOD_INLINE)) throw new IllegalArgumentException("key method must be inline"); if (mkiLength < 0 || mkiLength > 128) throw new IllegalArgumentException("mki length must be in range 1..128 inclusive or 0 to indicate default"); this.key = key; this.lifetime = lifetime; this.mki = mki; this.mkiLength = mkiLength; } /** * Creates a new instance of this class from the textual representation. * * @param keyParam The textual representation of the key parameter. */ public SrtpKeyParam(String keyParam) { if (!keyParam.startsWith(keyMethod + ":")) throw new IllegalArgumentException("Unknown key method in <" + keyParam + ">"); keyParam = keyParam.substring(KEYMETHOD_INLINE.length() + 1); String[] parts = keyParam.split("\\|"); key = Base64.decodeBase64(parts[0]); if(key.length == 0) throw new IllegalArgumentException("key must be present"); int partIndex = 1; if (parts.length > 1 && !parts[1].contains(":")) { if(parts[1].startsWith("2^")) lifetime = (int)Math.pow(2, Double.valueOf(parts[1].substring(2))); else lifetime = Integer.valueOf(parts[1]); partIndex++; } if (parts.length > partIndex && parts[partIndex].contains(":")) { String[] mkiParts = parts[partIndex].split(":"); mki = Integer.valueOf(mkiParts[0]); mkiLength = Integer.valueOf(mkiParts[1]); if (mkiLength < 1 || mkiLength > 128) throw new IllegalArgumentException("mki length must be in range 1..128 inclusive"); } } /** * The key method for this key parameter. * @return {@value #KEYMETHOD_INLINE} */ @Override public String getKeyMethod() { return keyMethod; } /** * Gets the concatenated master key and salt. * @return the concatenated master key and salt. */ public byte[] getKey() { return key; } /** * Gets the master key lifetime (max number of SRTP or SRTCP packets using * this master key) * * @return The master key lifetime. */ public int getLifetime() { return lifetime; } /** * Gets the master key identifier in the SRTP packets. * @return The master key identifier in the SRTP packets. */ public int getMki() { return mki; } /** * Gets the length of the MKI field in SRTP packets * @return The length of the MKI field in SRTP packets. */ public int getMkiLength() { return mkiLength; } @Override public String encode() { StringBuilder sb = new StringBuilder(); sb.append(keyMethod); sb.append(':'); sb.append(StringUtils.newStringUtf8(Base64.encodeBase64(key, false))); if (lifetime > 0) { sb.append('|'); sb.append(lifetime); } if (mkiLength > 0) { sb.append('|'); sb.append(mki); sb.append(':'); sb.append(mkiLength); } return sb.toString(); } } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/SrtpSDesFactory.java000066400000000000000000000066771275634304500250340ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.util.Random; import ch.imvs.sdes4j.*; /** * Factory for the SRTP grammar of RFC4568. * * @author Ingo Bauersachs */ public class SrtpSDesFactory implements SDesFactory { private Random r = null; /** * Creates an SRTP crypto attribute with the specified parameters, for use in an SDP. *

* If no random generator is set with {@link #setRandomGenerator(Random)} then the * SHA1PRNG, or if not available, the system's default {@link SecureRandom} will be used. * * @param tag decimal number used as an identifier for a particular crypto attribute * @param keyAlg identifier that describes the encryption and authentication algorithms * @return SRTP crypto attribute without session parameters. */ public SrtpCryptoAttribute createCryptoAttribute(int tag, String keyAlg) { return createCryptoAttribute(tag, keyAlg, null); } /** * Creates an SRTP crypto attribute with the specified parameters, for use in an SDP. * * @param tag decimal number used as an identifier for a particular crypto attribute * @param keyAlg identifier that describes the encryption and authentication algorithms * @param params Session parameters for the crypto attribute * @return SRTP crypto attribute without session parameters. */ public SrtpCryptoAttribute createCryptoAttribute(int tag, String keyAlg, SrtpSessionParam[] params) { SrtpCryptoSuite suite = createCryptoSuite(keyAlg); byte[] keyData = new byte[(suite.getEncKeyLength() + suite.getSaltKeyLength()) / 8]; getRandom().nextBytes(keyData); SrtpKeyParam key = new SrtpKeyParam( SrtpKeyParam.KEYMETHOD_INLINE, keyData, 0, 0, 0 ); return new SrtpCryptoAttribute(tag, suite, new SrtpKeyParam[] { key }, params); } private Random getRandom(){ if(r == null){ try { r = SecureRandom.getInstance("SHA1PRNG"); } catch (NoSuchAlgorithmException e) { r = new SecureRandom(); } } return r; } @Override public void setRandomGenerator(Random r) { this.r = r; } @Override public SrtpCryptoAttribute createCryptoAttribute() { return new SrtpCryptoAttribute(); } @Override public SrtpCryptoSuite createCryptoSuite(String suite) { return new SrtpCryptoSuite(suite); } @Override public SrtpKeyParam createKeyParam(String keyParam) { return new SrtpKeyParam(keyParam); } @Override public SrtpKeyParam[] createKeyParamArray(int size) { return new SrtpKeyParam[size]; } @Override public SrtpSessionParam createSessionParam(String sessionParam) { return SrtpSessionParam.create(sessionParam); } @Override public SrtpSessionParam[] createSessionParamArray(int size) { return new SrtpSessionParam[size]; } } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/SrtpSessionParam.java000066400000000000000000000032431275634304500252340ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import ch.imvs.sdes4j.SessionParam; /** * Base class for SRTP specific session parameters. * * @author Ingo Bauersachs */ public abstract class SrtpSessionParam implements SessionParam { SrtpSessionParam() { } /** * Creates instances from the text based representation of SRTP session parameters. * * @param param The text based representation of a session parameter. * @return The instance of a SRTP session parameter. */ public static SrtpSessionParam create(String param) { if (param.startsWith("KDR=")) return new KdrSessionParam(param); else if (param.equals("UNENCRYPTED_SRTP")) return new PlainSrtpSessionParam(); else if (param.equals("UNENCRYPTED_SRTCP")) return new PlainSrtcpSessionParam(); else if (param.equals("UNAUTHENTICATED_SRTP")) return new NoAuthSessionParam(); else if (param.startsWith("FEC_ORDER=")) return new FecOrderSessionParam(param); else if (param.startsWith("FEC_KEY=")) return new FecKeySessionParam(param); else if (param.startsWith("WSH=")) return new WshSessionParam(param); throw new IllegalArgumentException("Unknown session parameter"); } } sdes4j-1.1.4/src/main/java/ch/imvs/sdes4j/srtp/WshSessionParam.java000066400000000000000000000034141275634304500250450ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; /** * SRTP defines the SRTP-WINDOW-SIZE [RFC3711, Section 3.3.2] parameter to * protect against replay attacks. The Window Size Hint (WSH) session parameter * provides a hint for how big this window should be to work satisfactorily. * * The minimum value is 64 [RFC3711]; however, this value may be considered too * low for some applications (e.g., video). * * @author Ingo Bauersachs */ public class WshSessionParam extends SrtpSessionParam { private int wsh; /** * Creates a new instance of this class from an integer. * * @param wsh The size of the window hint. */ public WshSessionParam(int wsh) { if (wsh < 64) throw new IllegalArgumentException("Minimum size is 64"); this.wsh = wsh; } /** * Creates a new instance of this class from the textual representation. * * @param param The textual representation of the WSH parameter. */ public WshSessionParam(String param) { wsh = Integer.valueOf(param.split("=")[1]); if (wsh < 64) throw new IllegalArgumentException("Minimum size is 64"); } /** * Gets the size of the window hint. * * @return the size of the window hint. */ public int getWindowSizeHint() { return wsh; } @Override public String encode() { return "WSH=" + wsh; } } sdes4j-1.1.4/src/test/000077500000000000000000000000001275634304500144705ustar00rootroot00000000000000sdes4j-1.1.4/src/test/java/000077500000000000000000000000001275634304500154115ustar00rootroot00000000000000sdes4j-1.1.4/src/test/java/AllTests.java000066400000000000000000000030331275634304500200060ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ import org.junit.runner.RunWith; import org.junit.runners.Suite; import ch.imvs.sdes4j.CryptoAttributeTest; import ch.imvs.sdes4j.srtp.FecKeySessionParamTest; import ch.imvs.sdes4j.srtp.FecOrderSessionParamTest; import ch.imvs.sdes4j.srtp.KdrSessionParamTest; import ch.imvs.sdes4j.srtp.NoAuthSessionParamTest; import ch.imvs.sdes4j.srtp.PlainSrtcpSessionParamTest; import ch.imvs.sdes4j.srtp.PlainSrtpSessionParamTest; import ch.imvs.sdes4j.srtp.SrtpCryptoSuiteTest; import ch.imvs.sdes4j.srtp.SrtpKeyParamTest; import ch.imvs.sdes4j.srtp.WshSessionParamTest; @RunWith(Suite.class) @Suite.SuiteClasses({ FecKeySessionParamTest.class, FecOrderSessionParamTest.class, KdrSessionParamTest.class, NoAuthSessionParamTest.class, PlainSrtcpSessionParamTest.class, PlainSrtpSessionParamTest.class, SrtpCryptoSuiteTest.class, SrtpKeyParamTest.class, WshSessionParamTest.class, CryptoAttributeTest.class }) public class AllTests { // the class remains completely empty, // being used only as a holder for the above annotations public static void main(String args[]) { org.junit.runner.JUnitCore.main("AllTests"); } }sdes4j-1.1.4/src/test/java/ch/000077500000000000000000000000001275634304500160035ustar00rootroot00000000000000sdes4j-1.1.4/src/test/java/ch/imvs/000077500000000000000000000000001275634304500167615ustar00rootroot00000000000000sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/000077500000000000000000000000001275634304500201555ustar00rootroot00000000000000sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/CryptoAttributeTest.java000066400000000000000000000306011275634304500250240ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; import ch.imvs.sdes4j.srtp.FecOrderSessionParam; import ch.imvs.sdes4j.srtp.NoAuthSessionParam; import ch.imvs.sdes4j.srtp.SrtpCryptoSuite; import ch.imvs.sdes4j.srtp.SrtpKeyParam; import ch.imvs.sdes4j.srtp.SrtpSDesFactory; public class CryptoAttributeTest { private SrtpSDesFactory f; @Before public void setUp() { f = new SrtpSDesFactory(); } @Test public void testEncodeSessionParamsString() { byte[] bkey = new byte[]{0}; SrtpCryptoSuite suite = f.createCryptoSuite(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80); SrtpKeyParam key = new SrtpKeyParam( SrtpKeyParam.KEYMETHOD_INLINE, bkey, 0, 0, 0 ); CryptoAttribute a = new CryptoAttribute( 1, suite, new KeyParam[] { key }, new SessionParam[] { new FecOrderSessionParam(FecOrderSessionParam.FEC_SRTP), new NoAuthSessionParam() } ); assertEquals(2, a.getSessionParams().length); assertEquals("FEC_ORDER=FEC_SRTP UNAUTHENTICATED_SRTP", a.getSessionParamsString()); } @Test public void testEncodeKeyParamsString() { byte[] bkey = new byte[]{0}; SrtpCryptoSuite suite = f.createCryptoSuite(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80); SrtpKeyParam key = new SrtpKeyParam( SrtpKeyParam.KEYMETHOD_INLINE, bkey, 0, 0, 0 ); CryptoAttribute a = new CryptoAttribute( 1, suite, new KeyParam[] { key, key }, null ); assertEquals(2, a.getKeyParams().length); assertEquals("inline:AA==;inline:AA==", a.getKeyParamsString()); assertEquals(0, a.getSessionParams().length); } @Test public void testParseMultipleKeyParams() { CryptoAttribute a = CryptoAttribute.create("1 AES_CM_128_HMAC_SHA1_80 inline:AA==|2^20|1:4;inline:AA==;inline:AA==|1024", f); assertEquals(3, a.getKeyParams().length); SrtpKeyParam kp1 = (SrtpKeyParam) a.getKeyParams()[0]; assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp1.getKeyMethod()); assertEquals(0x100000, kp1.getLifetime()); assertEquals(1, kp1.getMki()); assertEquals(4, kp1.getMkiLength()); SrtpKeyParam kp2 = (SrtpKeyParam) a.getKeyParams()[1]; assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp2.getKeyMethod()); assertEquals(0, kp2.getLifetime()); assertEquals(0, kp2.getMki()); assertEquals(0, kp2.getMkiLength()); SrtpKeyParam kp3 = (SrtpKeyParam) a.getKeyParams()[2]; assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp3.getKeyMethod()); assertEquals(1024, kp3.getLifetime()); assertEquals(0, kp3.getMki()); assertEquals(0, kp3.getMkiLength()); assertEquals("inline:AA==|1048576|1:4;inline:AA==;inline:AA==|1024", a.getKeyParamsString()); } @Test public void testParseExample1() { CryptoAttribute a = CryptoAttribute.create("1 AES_CM_128_HMAC_SHA1_80 inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz|2^20|1:4 FEC_ORDER=FEC_SRTP", f); validateExample2(a); } @Test(expected=IllegalArgumentException.class) public void testParseWithoutKeyParameter() { new CryptoAttribute(1, new SrtpCryptoSuite(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80), null, null); } @Test(expected=IllegalArgumentException.class) public void testParseWithoutKeyParameterString() { CryptoAttribute.create("1 AES_CM_128_HMAC_SHA1_80", f); } @Test(expected=IllegalArgumentException.class) public void testParseWithTagAboveLimitString() { CryptoAttribute.create("1234567890 AES_CM_128_HMAC_SHA1_80", f); } @Test(expected=IllegalArgumentException.class) public void testParseWithTagBelowLimitString() { CryptoAttribute.create("-1 AES_CM_128_HMAC_SHA1_80", f); } @Test(expected=IllegalArgumentException.class) public void testParseWithTagAboveLimit() { new CryptoAttribute(1234567890, null, null, null); } @Test(expected=IllegalArgumentException.class) public void testParseWithTagBelowLimit() { new CryptoAttribute(-1, null, null, null); } @Test(expected=IllegalArgumentException.class) public void testParseWithoutCryptoSuite() { new CryptoAttribute(1, null, null, null); } @Test public void testParseExample1Xmpp() { CryptoAttribute a = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz|2^20|1:4", "FEC_ORDER=FEC_SRTP", f); validateExample2(a); } private void validateExample2(CryptoAttribute a) { assertEquals(1, a.getTag()); assertEquals(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80, a.getCryptoSuite().encode()); assertEquals(1, a.getKeyParams().length); SrtpKeyParam kp = (SrtpKeyParam) a.getKeyParams()[0]; assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(0x100000, kp.getLifetime()); assertEquals(1, kp.getMki()); assertEquals(4, kp.getMkiLength()); assertEquals(1, a.getSessionParams().length); assertEquals(FecOrderSessionParam.FEC_SRTP, ((FecOrderSessionParam) a.getSessionParams()[0]).getMode()); assertEquals("FEC_ORDER=FEC_SRTP", a.getSessionParamsString()); } @Test public void testParseExample2() { CryptoAttribute a = CryptoAttribute.create("2 F8_128_HMAC_SHA1_80 inline:MTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5QUJjZGVm|2^20|1:4;inline:QUJjZGVmMTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5|2^20|2:4\t\tFEC_ORDER=FEC_SRTP", f); assertEquals(2, a.getTag()); assertEquals(SrtpCryptoSuite.F8_128_HMAC_SHA1_80, a.getCryptoSuite().encode()); assertEquals(2, a.getKeyParams().length); SrtpKeyParam kp1 = (SrtpKeyParam) a.getKeyParams()[0]; assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp1.getKeyMethod()); assertEquals(0x100000, kp1.getLifetime()); assertEquals(1, kp1.getMki()); assertEquals(4, kp1.getMkiLength()); assertEquals(1, ((SrtpKeyParam) a.getKeyParams()[0]).getMki()); assertEquals(2, ((SrtpKeyParam) a.getKeyParams()[1]).getMki()); assertEquals(1, a.getSessionParams().length); assertEquals(FecOrderSessionParam.FEC_SRTP, ((FecOrderSessionParam) a.getSessionParams()[0]).getMode()); assertEquals("2 F8_128_HMAC_SHA1_80 inline:MTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5QUJjZGVm|1048576|1:4;inline:QUJjZGVmMTIzNDU2Nzg5QUJDREUwMTIzNDU2Nzg5|1048576|2:4 FEC_ORDER=FEC_SRTP", a.encode()); } @Test public void testParseExample3() { CryptoAttribute a = CryptoAttribute.create("1 AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", f); validateExample3(a); } @Test public void testParseExample3Xmpp() { CryptoAttribute a = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", null, f); validateExample3(a); } @Test public void testParseExample3bXmpp() { CryptoAttribute a = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); validateExample3(a); } private void validateExample3(CryptoAttribute a) { assertEquals(1, a.getTag()); assertEquals(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80, a.getCryptoSuite().encode()); assertEquals(1, a.getKeyParams().length); SrtpKeyParam kp = (SrtpKeyParam) a.getKeyParams()[0]; assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(0x100000, kp.getLifetime()); assertEquals(1, kp.getMki()); assertEquals(4, kp.getMkiLength()); assertEquals(0, a.getSessionParams().length); assertEquals("inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|1048576|1:4", a.getKeyParamsString()); assertEquals(null, a.getSessionParamsString()); } @Test public void testCreateAttribute() { byte[] bkey = new byte[]{0}; SrtpCryptoSuite suite = f.createCryptoSuite(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80); SrtpKeyParam key = new SrtpKeyParam( SrtpKeyParam.KEYMETHOD_INLINE, bkey, 0, 0, 0 ); CryptoAttribute a = new CryptoAttribute(1, suite, new KeyParam[] { key }, null); assertEquals("1 AES_CM_128_HMAC_SHA1_80 inline:AA==", a.encode()); assertEquals(0, a.getSessionParams().length); } @Test public void testEquals() { CryptoAttribute a = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute b = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute c = CryptoAttribute.create("2", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute d = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_32", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute e = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^21|1:4", "", f); CryptoAttribute g = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "FEC_ORDER=FEC_SRTP", f); CryptoAttribute h = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "FEC_ORDER=FEC_SRTP", f); CryptoAttribute i = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR", "FEC_ORDER=FEC_SRTP", f); assertEquals(a, b); assertEquals(g, h); assertNotEquals(a, c); assertNotEquals(a, d); assertNotEquals(a, e); assertNotEquals(a, g); assertNotEquals(a, h); assertNotEquals(a, i); assertNotEquals(d, e); assertNotEquals(h, i); } @Test public void testHashcode() { CryptoAttribute a = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute b = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute c = CryptoAttribute.create("2", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute d = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_32", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "", f); CryptoAttribute e = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^21|1:4", "", f); CryptoAttribute g = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "FEC_ORDER=FEC_SRTP", f); CryptoAttribute h = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:4", "FEC_ORDER=FEC_SRTP", f); CryptoAttribute i = CryptoAttribute.create("1", "AES_CM_128_HMAC_SHA1_80", "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR", "FEC_ORDER=FEC_SRTP", f); assertEquals(a.hashCode(), b.hashCode()); assertEquals(g.hashCode(), h.hashCode()); assertNotEquals(a.hashCode(), c.hashCode()); assertNotEquals(a.hashCode(), d.hashCode()); assertNotEquals(a.hashCode(), e.hashCode()); assertNotEquals(a.hashCode(), g.hashCode()); assertNotEquals(a.hashCode(), h.hashCode()); assertNotEquals(a.hashCode(), i.hashCode()); assertNotEquals(d.hashCode(), e.hashCode()); assertNotEquals(h.hashCode(), i.hashCode()); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/000077500000000000000000000000001275634304500211455ustar00rootroot00000000000000sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/FecKeySessionParamTest.java000066400000000000000000000057701275634304500263540ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; public class FecKeySessionParamTest { private SrtpKeyParam kp1; private SrtpKeyParam kp2; @Before public void setUp() { kp1 = new SrtpKeyParam(SrtpKeyParam.KEYMETHOD_INLINE, new byte[0], 0, 0, 0){ @Override public String encode() { return "KP1"; } }; kp2 = new SrtpKeyParam(SrtpKeyParam.KEYMETHOD_INLINE, new byte[0], 0, 0, 0){ @Override public String encode() { return "KP2"; } }; } @Test public void testFecKeySessionParamSrtpKeyParamArray() { FecKeySessionParam fecOne = new FecKeySessionParam(new SrtpKeyParam[] { kp1 }); assertEquals("FEC_KEY=KP1", fecOne.encode()); FecKeySessionParam fecTwo = new FecKeySessionParam(new SrtpKeyParam[] { kp1, kp2 }); assertEquals("FEC_KEY=KP1;KP2", fecTwo.encode()); } @Test public void testFecKeySessionParamString() { String oneKeyParam = "FEC_KEY=KP1"; FecKeySessionParam fecKeyOne = new FecKeySessionParam(oneKeyParam){ @Override protected SrtpKeyParam createSrtpKeyParam(final String p) { SrtpKeyParam kp = new SrtpKeyParam(SrtpKeyParam.KEYMETHOD_INLINE, new byte[0], 0, 0, 0){ @Override public String encode() { return p; } }; return kp; } }; assertEquals(1, fecKeyOne.getKeyParams().length); assertEquals(oneKeyParam, fecKeyOne.encode()); String twoKeyParam = "FEC_KEY=KP1;KP2"; FecKeySessionParam fecKeyTwo = new FecKeySessionParam(twoKeyParam){ @Override protected SrtpKeyParam createSrtpKeyParam(final String p) { SrtpKeyParam kp = new SrtpKeyParam(SrtpKeyParam.KEYMETHOD_INLINE, new byte[0], 0, 0, 0){ @Override public String encode() { return p; } }; return kp; } }; assertEquals(2, fecKeyTwo.getKeyParams().length); assertEquals(twoKeyParam, fecKeyTwo.encode()); } @Test public void testGetKeyParams() { FecKeySessionParam fecTwo = new FecKeySessionParam(new SrtpKeyParam[] { kp1, kp2 }); assertEquals(2, fecTwo.getKeyParams().length); assertEquals(kp1, fecTwo.getKeyParams()[0]); assertEquals(kp2, fecTwo.getKeyParams()[1]); } }sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/FecOrderSessionParamTest.java000066400000000000000000000031471275634304500266730ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class FecOrderSessionParamTest { @Test public void testFecOrderSessionParamInt() { FecOrderSessionParam fecSrtp = new FecOrderSessionParam(FecOrderSessionParam.FEC_SRTP); assertEquals(FecOrderSessionParam.FEC_SRTP, fecSrtp.getMode()); FecOrderSessionParam srtpFec = new FecOrderSessionParam(FecOrderSessionParam.SRTP_FEC); assertEquals(FecOrderSessionParam.SRTP_FEC, srtpFec.getMode()); } @Test(expected=IllegalArgumentException.class) public void testFecOrderSessionParamIntInvalid() { new FecOrderSessionParam(3); } @Test public void testFecOrderSessionParamString() { String input1 = "FEC_ORDER=FEC_SRTP"; FecOrderSessionParam fecSrtp = new FecOrderSessionParam(input1); assertEquals(FecOrderSessionParam.FEC_SRTP, fecSrtp.getMode()); assertEquals(input1, fecSrtp.encode()); String input2 = "FEC_ORDER=SRTP_FEC"; FecOrderSessionParam srtpFec = new FecOrderSessionParam(FecOrderSessionParam.SRTP_FEC); assertEquals(FecOrderSessionParam.SRTP_FEC, srtpFec.getMode()); assertEquals(input2, srtpFec.encode()); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/KdrSessionParamTest.java000066400000000000000000000051771275634304500257270ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class KdrSessionParamTest { @Test public void testKdrSessionParamInt() { KdrSessionParam kdr0 = new KdrSessionParam(0); assertEquals(0, kdr0.getKeyDerivationRate()); assertEquals(1, kdr0.getKeyDerivationRateExpanded()); assertEquals("KDR=0", kdr0.encode()); KdrSessionParam kdr1 = new KdrSessionParam(1); assertEquals(1, kdr1.getKeyDerivationRate()); assertEquals(2, kdr1.getKeyDerivationRateExpanded()); assertEquals("KDR=1", kdr1.encode()); KdrSessionParam kdr24 = new KdrSessionParam(24); assertEquals(24, kdr24.getKeyDerivationRate()); assertEquals(0x1000000, kdr24.getKeyDerivationRateExpanded()); assertEquals("KDR=24", kdr24.encode()); } @Test(expected=IllegalArgumentException.class) public void testKdrSessionParamIntInvalidLower() { new KdrSessionParam(-1); } @Test(expected=IllegalArgumentException.class) public void testKdrSessionParamIntInvalidUpper() { new KdrSessionParam(25); } @Test public void testKdrSessionParamString() { String input0 = "KDR=0"; KdrSessionParam kdr0 = new KdrSessionParam(input0); assertEquals(0, kdr0.getKeyDerivationRate()); assertEquals(1, kdr0.getKeyDerivationRateExpanded()); assertEquals(input0, kdr0.encode()); String input1 = "KDR=1"; KdrSessionParam kdr1 = new KdrSessionParam(input1); assertEquals(1, kdr1.getKeyDerivationRate()); assertEquals(2, kdr1.getKeyDerivationRateExpanded()); assertEquals(input1, kdr1.encode()); String input24 = "KDR=24"; KdrSessionParam kdr24 = new KdrSessionParam(input24); assertEquals(24, kdr24.getKeyDerivationRate()); assertEquals(0x1000000, kdr24.getKeyDerivationRateExpanded()); assertEquals(input24, kdr24.encode()); } @Test(expected=IllegalArgumentException.class) public void testKdrSessionParamStringInvalidLower() { new KdrSessionParam("KDR=-1"); } @Test(expected=IllegalArgumentException.class) public void testKdrSessionParamStringInvalidUpper() { new KdrSessionParam("KDR=25"); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/NoAuthSessionParamTest.java000066400000000000000000000012101275634304500263650ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class NoAuthSessionParamTest { @Test public void testToString() { assertEquals("UNAUTHENTICATED_SRTP", new NoAuthSessionParam().encode()); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/PlainSrtcpSessionParamTest.java000066400000000000000000000012151275634304500272530ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class PlainSrtcpSessionParamTest { @Test public void testToString() { assertEquals("UNENCRYPTED_SRTCP", new PlainSrtcpSessionParam().encode()); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/PlainSrtpSessionParamTest.java000066400000000000000000000012121275634304500271050ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class PlainSrtpSessionParamTest { @Test public void testToString() { assertEquals("UNENCRYPTED_SRTP", new PlainSrtpSessionParam().encode()); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/SrtpCryptoAttributeTest.java000066400000000000000000000022071275634304500266660ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; public class SrtpCryptoAttributeTest { private SrtpSDesFactory f; @Before public void setUp() { f = new SrtpSDesFactory(); } @Test public void testGetSessionParams(){ byte[] bkey = new byte[]{0}; SrtpCryptoSuite suite = f.createCryptoSuite(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80); SrtpKeyParam key = new SrtpKeyParam( SrtpKeyParam.KEYMETHOD_INLINE, bkey, 0, 0, 0 ); SrtpCryptoAttribute ca = new SrtpCryptoAttribute(1, suite, new SrtpKeyParam[] { key }, null); assertEquals(0, ca.getSessionParams().length); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/SrtpCryptoSuiteTest.java000066400000000000000000000016411275634304500260150ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class SrtpCryptoSuiteTest { @Test public void testToString() { assertEquals("AES_CM_128_HMAC_SHA1_80", new SrtpCryptoSuite(SrtpCryptoSuite.AES_CM_128_HMAC_SHA1_80).encode()); } @Test(expected=IllegalArgumentException.class) public void testSrtpCryptoSuiteInvalid() { new SrtpCryptoSuite("invalid suite"); } // more tests would only duplicate the dumb behavior of the constructor... } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/SrtpKeyParamTest.java000066400000000000000000000116531275634304500252400ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class SrtpKeyParamTest { @Test(expected=IllegalArgumentException.class) public void testSrtpKeyParamInvalidKeyMethod() { new SrtpKeyParam("invalid", null, 0, 0, 0); } @Test public void testSrtpKeyParamKeyOnly() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2"; SrtpKeyParam kp = new SrtpKeyParam(input); assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(30, kp.getKey().length); assertEquals(0, kp.getLifetime()); assertEquals(0, kp.getMki()); assertEquals(0, kp.getMkiLength()); assertEquals(input, kp.encode()); } @Test public void testSrtpKeyParamKeyAndLifetimeNumeric() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1234"; SrtpKeyParam kp = new SrtpKeyParam(input); assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(30, kp.getKey().length); assertEquals(1234, kp.getLifetime()); assertEquals(0, kp.getMki()); assertEquals(0, kp.getMkiLength()); assertEquals(input, kp.encode()); } @Test public void testSrtpKeyParamKeyAndLifetimeExponential() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|2^10"; SrtpKeyParam kp = new SrtpKeyParam(input); assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(30, kp.getKey().length); assertEquals(1024, kp.getLifetime()); assertEquals(0, kp.getMki()); assertEquals(0, kp.getMkiLength()); assertEquals("inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1024", kp.encode()); } @Test public void testSrtpKeyParamKeyAndMki() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1:128"; SrtpKeyParam kp = new SrtpKeyParam(input); assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(30, kp.getKey().length); assertEquals(0, kp.getLifetime()); assertEquals(1, kp.getMki()); assertEquals(128, kp.getMkiLength()); assertEquals(input, kp.encode()); } @Test(expected=IllegalArgumentException.class) public void testSrtpKeyParamKeyAndMkiLower() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1:0"; new SrtpKeyParam(input); } @Test(expected=IllegalArgumentException.class) public void testSrtpKeyParamKeyAndMkiUpper() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1:129"; new SrtpKeyParam(input); } @Test(expected=IllegalArgumentException.class) public void testSrtpKeyParamKeyAndMkiInvalidNoMki() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|:129"; new SrtpKeyParam(input); } @Test(expected=ArrayIndexOutOfBoundsException.class) public void testSrtpKeyParamKeyAndMkiInvalidNoMkiLength() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1:"; new SrtpKeyParam(input); } @Test(expected=IllegalArgumentException.class) public void testSrtpKeyParamKeyInvalidLifetime() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2||1:129"; new SrtpKeyParam(input); } @Test(expected=IllegalArgumentException.class) public void testSrtpKeyParamInvalidKey() { String input = "inline:{=="; new SrtpKeyParam(input); } @Test public void testSrtpKeyParamKeyAndLifetimeNumericAndMki() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1234|1:1"; SrtpKeyParam kp = new SrtpKeyParam(input); assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(30, kp.getKey().length); assertEquals(1234, kp.getLifetime()); assertEquals(1, kp.getMki()); assertEquals(1, kp.getMkiLength()); assertEquals(input, kp.encode()); } @Test public void testSrtpKeyParamKeyAndLifetimeExponetialAndMki() { String input = "inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|2^10|1:1"; SrtpKeyParam kp = new SrtpKeyParam(input); assertEquals(SrtpKeyParam.KEYMETHOD_INLINE, kp.getKeyMethod()); assertEquals(30, kp.getKey().length); assertEquals(1024, kp.getLifetime()); assertEquals(1, kp.getMki()); assertEquals(1, kp.getMkiLength()); assertEquals("inline:YUJDZGVmZ2hpSktMbW9QUXJzVHVWd3l6MTIzNDU2|1024|1:1", kp.encode()); } } sdes4j-1.1.4/src/test/java/ch/imvs/sdes4j/srtp/WshSessionParamTest.java000066400000000000000000000023531275634304500257410ustar00rootroot00000000000000/* * SDES4J * Java implementation of SDES (Security Descriptions for Media Streams, * RFC 4568). * * Copyright (C) 2011 FHNW * University of Applied Sciences Northwestern Switzerland (FHNW) * School of Engineering * Institute of Mobile and Distributed Systems (IMVS) * http://sdes4j.imvs.ch * * Distributable under LGPL license, see terms of license at gnu.org. */ package ch.imvs.sdes4j.srtp; import static org.junit.Assert.*; import org.junit.Test; public class WshSessionParamTest { @Test public void testWshSessionParamInt() { WshSessionParam wsh = new WshSessionParam(64); assertEquals(64, wsh.getWindowSizeHint()); assertEquals("WSH=64", wsh.encode()); } @Test(expected=IllegalArgumentException.class) public void testWshSessionParamIntLower() { new WshSessionParam(63); } @Test public void testWshSessionParamString() { String input = "WSH=64"; WshSessionParam wsh = new WshSessionParam(input); assertEquals(64, wsh.getWindowSizeHint()); assertEquals(input, wsh.encode()); } @Test(expected=IllegalArgumentException.class) public void testWshSessionParamStringLower() { new WshSessionParam("WSH=63"); } }